SetProperty on Hotspot from combining Inventory items

Started by Nadarian, Fri 29/05/2020 09:42:45

Previous topic - Next topic

Nadarian

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! :)
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Khris

To change room hotspots (and objects) from the global script, you need something like:

Code: ags
  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.

Nadarian

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

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?  :-\
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Khris

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
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)

Nadarian

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!!
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Khris

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

Nadarian

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!
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

SMF spam blocked by CleanTalk