Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: sloppy on Thu 27/10/2005 04:49:09

Title: Another variable question...
Post by: sloppy on Thu 27/10/2005 04:49:09
I just can't get my head around variables yet.  Maybe if I can master this one in my game, others will come easier.

I'm sure this is very simple: I'm in a room that has a TV.  When I look at it, I want the dialogue to say, "I think I'll turn on the TV" or something like that.  But after the phone rings, I go to another room and the person on the phone tells me I have to rush off somewhere.  So after that, when I look at the TV, I want the message to say, "No time to watch after that conversation!"

Simple right?  I can't do it.  And the manual doesn't seem to help.
Title: Re: Another variable question...
Post by: Ashen on Thu 27/10/2005 10:37:18
Do a quick forum search - similar questions are asked a lot, you'll probably find an answer there.
Otherwise, what have you tried so far?

Basically:

1. Create an int in the global script, export in and import it into the header (see this recent thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23151.0) for details.
This now means you can change or access watchtv from any room. (You could also use a GlobalInt instead of exporting/importing your own).

2. In the script for the TV object/hotspot (whichever it is):

if (watchtv ==0) { // Can watch TV
  player.Say("I think I'll watch a bit of TV.");
  //whatever else you want to do
}

else if (watchtv == 1) { // Can't watch TV
  player.Say("No time for that now!");
}


3. At the end of the telephone call, add the line:

watchtv = 1;

(Look up Get/SetGlobalInt() for how to use GlobalInts.)

And, if at some point you want to be able to watch TV again, just set watchtv back to 0.
Title: Re: Another variable question...
Post by: sloppy on Thu 27/10/2005 15:20:19
Okay, I kind of get what I'm supposed to do.  But now a problem.  I've declared the variable (watch_tv) in the global script and then exported it.  The phone conversation is in another room, so I've imported the variable at the beginning of that room script.  At the end of the conversation, I put "watch_tv = 1"
Now when I interact with the phone in the first room to start the conversation, I get an error "Unable to create local script: Runtime error: unresolved import 'watch_tv'."
Any ideas?
Title: Re: Another variable question...
Post by: Ashen on Thu 27/10/2005 15:44:44
You need to import it in the Script Header (from the 'Script' drop down menu, or Ctrl-H), rather than the Room Script. Try that, see if it works (don't fopget to remove the import from the room script).
Title: Re: Another variable question...
Post by: sloppy on Thu 27/10/2005 15:54:52
That was it.  Now it works.  Thanks for your help!