Another variable question...

Started by sloppy, Thu 27/10/2005 04:49:09

Previous topic - Next topic

sloppy

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.

Ashen

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

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

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.
I know what you're thinking ... Don't think that.

sloppy

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?

Ashen

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).
I know what you're thinking ... Don't think that.

sloppy

That was it.  Now it works.  Thanks for your help!

SMF spam blocked by CleanTalk