Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sat 01/05/2004 19:53:30

Title: Dialog--->Variable help!!
Post by: on Sat 01/05/2004 19:53:30
Hey-
  I'm REALLY new to ags, downloaded it about 3 weeks ago - I've  learned enough stuff from tutorials to be able to start making a game I have in mind.. but I've struck a problem.
  I need to know how do you a make dialog option you choose do something in the game. Example: You can't get through a door untill characterX tells you how - it is possible to talk to characterX without finding this info out, but when you DO ask him the right things he'll tell you and you can then open door. Simple? Sorry if it is, but I can't find it in the tutorials or anything.
Title: Re:Dialog--->Variable help!!
Post by: .. on Sat 01/05/2004 20:05:29
Use Dialog request.

If you don't know how look it up inthe manual :)
Title: Re:Dialog--->Variable help!!
Post by: strazer on Sat 01/05/2004 20:19:36
There is also another way. With

set-globalint GI VAL

you can set global integer variables from within a dialog script:

@1 // you ask characterX how to open the door
charx: Use a key, dumbass!
ego: Ah, right, thanks.
set-globalint 1 1 // sets global integer 1 to value 1
return

You can then check this global integer when you try to open the door:

if (GetGlobalInt(1) == 1) {
myOpenDoor();
}
Title: Re:Dialog--->Variable help!!
Post by: on Sat 01/05/2004 20:25:50
WOW! Thanks loads... sorry if that was a bit dumb. But Cheers! "Johnny's Odyssey Part One: The Wind Below." Coming Soon.

(Sooner now)
Title: Re: Dialog--->Variable help!!
Post by: Johnny Odd on Thu 06/05/2004 20:32:31
Ok. I thought I had the problem nailed - but I didn't and then I just kinda forgot about untill I tried to run my game.
I have no good experience of script work and am not very good. In fact I'm terrible.

I can easily SET the global int in the dialog script - but where abouts do I put

if (GetGlobalInt(1) == 1) {
myOpenDoor();
}

Is it interaction with door --> run script?
Don't I somewhere have to state what exactly My Door is? ???

Sorry if this is some easy task - but I really am not good at scripting.... It'd be great if someone could tell me what I have to do here!!
Title: Re: Dialog--->Variable help!!
Post by: strazer on Thu 06/05/2004 20:47:20
QuoteIs it interaction with door --> run script?

Correct.

The myOpenDoor(); part was just a placeholder for whatever you want to do when the player opens the door. You could do sophisticated door animations here for example.
I suggest you keep it simple at first and maybe just go to the new room:

if (GetGlobalInt(1) == 1) {
  PlaySound(2); // plays sound2.mp3 (door opening)
  NewRoomEx(2, 50, 150); // puts player in room 2 at coordinates x=50 and y=150
}

QuoteDon't I somewhere have to state what exactly My Door is?

I don't know what you mean exactly.
Of course you have to draw a hotspot or put an object where your door is. Then press the "Interaction" button and put the above lines in
"Interact with hotspot" --> "Run script" for example.
Title: Re: Dialog--->Variable help!!
Post by: Johnny Odd on Thu 06/05/2004 21:19:53
That's really great!  ;DThanks loads ;D - It works now.
BTW, I meant that if I was going to use a script comand like MyOpenDoor, or something, the script would not recognise that term would it?
How would I make it know what I meant?
But I got my little door puzzle working anyway thanks to you.
CHEERS!!  :D
Title: Re: Dialog--->Variable help!!
Post by: strazer on Thu 06/05/2004 21:35:33
QuoteBTW, I meant that if I was going to use a script comand like MyOpenDoor, or something, the script would not recognise that term would it?

Correct.
For it work, you would need a custom function named myOpenDoor().

If you have several interactions that all require the same code, you can put this code into a custom function that you can reuse for other interactions.

For example, if you want the door to open both if you use a key on it or you just interact with it:

Room script (anywhere but other functions, preferrably on top)

function myOpenDoor() { // define custom function
  if (GetGlobalInt(1) == 1) {
    PlaySound(2);
    NewRoomEx(2, 50, 150);
  }
}

Interact with door

  myOpenDoor(); // execute the above function

Use inventory on door

if (player.activeinv == 2) { // player used key on door
  myOpenDoor();
}

In this example if have put the GI condition in the myOpenDoor function as well, since it is used by both interactions.