SOLVED Problem with items turning into visible after using an item on an hotspot

Started by beenf, Wed 08/06/2011 12:58:55

Previous topic - Next topic

beenf

So my goal is.
I want to use an item from inventory on an hotspot in room number 1.
if i use that then in room 2 object1 turns into invisible and other 3 objects turn into visible

This is what I got so far:
This is in the room where the items have to turn visible and invisible
Code: ags

function room_Load()
{
 if(MySwitch2 == 1)
 {
   opomm1.Visible = false;
   opomm2.Visible = true;
   oglass.Visible = true;
   oSquare.Visible = true;
 }
}


This is from the room I use item on hotspot:
Code: ags

function hHotspot3_UseInv()
{
if (player.ActiveInventory == iDeadcat)
{
  player.Walk(207, 135, eBlock);
  player.LoseInventory(iDeadcat);
  if(MySwitch2 == 0)
  MySwitch2 = 1;
  }
}


But when I go to game after I use the item on hotspot and going to the second room all the items are as they were before the action.

Hernald

I take it MySwitch2 is a global? Have you accidentally set the value back  to 0 after room_Load ?
As an aside, this looks like a good place to use a bool rather than an integer.
Or does MySwitch2 take any values other than 0 and 1? if so, that could explain it not working.

Khris

Where did you declare MySwitch2?
I suspect you've declared it in Global.ash because that creates a separate variable for each room.

Best use the Global variables pane.

beenf

I did a global variable like this: http://i36.photobucket.com/albums/e10/beenf/myswitch2.jpg
I tried to follow the MySwitch global variable which I used for removing Walkable area, but I don't understand what I did wrong.
Not very good using Global Variables

Hernald

Yes, that's the globals pane.
If you right click on one of the places you set MySwitch2 it will give you the option to list all the places it is used. You may find that useful in seeing if it is used somewhere other than the places you've mentioned.

beenf

Quote from: Hernald on Wed 08/06/2011 15:06:36
Yes, that's the globals pane.
If you right click on one of the places you set MySwitch2 it will give you the option to list all the places it is used. You may find that useful in seeing if it is used somewhere other than the places you've mentioned.
I don't understand what do I have to right click on?
As places do you mean where I wrote the MySwitch2 script or what?
Sorry, I'm just new to all this.

If anyone has a better/easier solution how to get what my goal is then they could tell me it aswell.

Hernald

Sorry, I'm quite new to this too. You right click on the word MySwitch2 in the script you have written. A list of options pop up, I think you choose the top one or second one.

As far as simplifying the code;
  if(MySwitch2 == 0)
  MySwitch2 = 1;
Can probably be replaced with just
  MySwitch2 = 1;
But that depends on what you are doing with it elsewhere.

Other than that what you are trying to do looks fairly straightforward.

Just a thought: There is a system variable on rooms that sets them back to there original state whenever the player returns if it's switched on. The default is off which it correct for what you're doing, you haven't switched it on have you?

beenf

Quote from: Hernald on Wed 08/06/2011 15:33:00
Just a thought: There is a system variable on rooms that sets them back to there original state whenever the player returns if it's switched on. The default is off which it correct for what you're doing, you haven't switched it on have you?
i don't think so. Where can I check that?

Hernald

In room edit, just below room number StateSaving should equal True. But according to the manual it's set to False if the room number is greater than 300.

How did you get on with the right-clicking?

beenf

It equals true.
About right clicking.
I clicked MySwitch2 in the script and chose Go to definition of mySwitch2, but nothing happened

Hernald

Try the second option; 'Find all Usages'.

beenf

There isn't such option
There is only:
Go to definition of MySwitch2
Go To Sprite (Doesn't let me use this)
Toggle Breakpoint
Cut
Copy
Paste

Hernald


beenf

3.1.2 SP1
If I download a newest one can I continue making the game in it?


beenf

But doesn't no one has a code how to get it working with my current version?
Or is it essential I download newer version and do the right click thingy?

Khris

No, stick to 3.1.2 for now, that's fine.

The only thing I can think of by now is that the room_Load function isn't linked and thus not executed. (If the other one weren't linked the player wouldn't walk there and lose the cat and you'd notice that so I assume that's happening.)

If you look at room 2's events (lightning bolt icon), does it say "room_Load" next to "Enters room before fade-in"?

beenf

Quote from: Khris on Wed 08/06/2011 18:38:51
If you look at room 2's events (lightning bolt icon), does it say "room_Load" next to "Enters room before fade-in"?
Yay ! This was the problem. Thnx, tho I should have noticed it myself, has happened to me before -.-. I often just go straight to script and type the function.

Khris

In case you missed this, AGS creates & links the function if you select the event, then click on the ...-button.

SMF spam blocked by CleanTalk