Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nadarian on Fri 29/05/2020 09:42:45

Title: SetProperty on Hotspot from combining Inventory items
Post by: Nadarian on Fri 29/05/2020 09:42:45
Hi again!

New newbie question...! I’m trying to change a property in a Hotspot from the General Script, when combining two different items.
When doing so, an error pops up because GeneralScript can’t find that Hotspot. I read something about importing/exporting things between script pages, but I really don’t know how it works nor if this is the way to solve my problem.

Thanks in advance! :)
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Khris on Fri 29/05/2020 11:33:27
To change room hotspots (and objects) from the global script, you need something like:

Code (ags) Select
  if (player.Room == 3) {
    hotspot[2].Enabled = false;
  }
  else player.Say("I shouldn't do that here.");


hotspot[] and object[] are global arrays that can be used to refer to the current room's hotspots and objects using the ID.
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Nadarian on Fri 29/05/2020 12:55:16
Thanks Khris!

I don't know if this is the case I'm exposing...! Let's see if I can explain myself better:

There's a Hotspot in a room which seems "useless" for the main character every time he looks at it.
At some point, you grab two objects that should be combined in the Inventory. Combining them gives the player a clue, and this should trigger that Hotspot to offer a different answer when the player looks at it again.

This is what I write in the GlobalScript when using these two objects on each other:

Code (ags) Select

function iTargeta_UseInv()
{
  switch(cRoger.ActiveInventory)
  {
      case  iFiltre:
        cRoger.Say("I si superposo el filtre amb la cartolina...?");
        hCapsesPaper.SetProperty("CapsesPaper", 2);


When I try to start the game, this error pops up:

"Undefined token: 'hCapsesPaper'"

I understand GlobalScript can't find this, because this is a Hotspot located in a specific room. So then.. what should I do to trigger different properties on hotspots or other things from the GlobalScript?  :-\
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Khris on Fri 29/05/2020 13:01:40
Yeah, that's what I was referring to. You pretty much replace  hCapsesPaper.SetProperty("CapsesPaper", 2);  with the lines I posted, replacing 3 and 2 with the room number and hotspot.ID respectively.

Code (ags) Select
function iTargeta_UseInv()
{
  switch(cRoger.ActiveInventory)
  {
      case  iFiltre:
        cRoger.Say("I si superposo el filtre amb la cartolina...?");
        if (player.Room == 3) {
          hotspot[2].SetProperty("CapsesPaper", 2);
        }


(note that adding a custom property adds it to *all* hotspots, so you might want to consider using a global variable instead)
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Nadarian on Fri 29/05/2020 14:23:28
Ok! With this I'm really close to get it!

But there's something I need to change to this script in order to make it work the way I'd like it to, and I don't know what it is...
Doing as you wrote, makes the SetProperty work as long as I combine the objects in the same room the hotspot is. Combining the objects in any other room in the game, gives the player the clue, but doesn't trigger the SetProperty. Would it be possible to make it work no matter the room you are in? But affecting that specific hotspot in a specific room, of course.

Thanks for all your help, Khris! I've already seen how active you are in this Forum!

EDIT:
Yes! As I said, I'm a complete newbie so please, be kind  :P But solved it all using Global Variables. Actually, didn't hear about them before... and they are a basic thing to know. Thanks again!!
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Khris on Fri 29/05/2020 20:21:46
Yes, with a global variable you can change the game's state regardless of the room you're in. Without them you'll only get so far.

I remember somebody getting really creative and adding invisible inventory items because they didn't know about them :-D
Title: Re: SetProperty on Hotspot from combining Inventory items
Post by: Nadarian on Sat 30/05/2020 10:59:15
Ha! I'm sure I'm making a bunch of noob mistakes in this first game also, but.. sincerely! I'm pretty happy about the results so far!!
I hope I can translate it into english and show it here when it's done!

Thanks, Khris!