Multiple Responses On Object

Started by ScottDoom, Thu 24/06/2004 07:39:08

Previous topic - Next topic

ScottDoom

I've never programmed before, so I decided to make a test game with a bunch of different scripts, as well as an intro, cut-scene, and outro. The game doesn't have a storyline or anything, I'm just practicing on scripting.

Anyways, I was reading through this tutorial and I came to the part about giving an object a different response to a command every time you click it. I followed the example exactly, but it's not working. It'll only display the first message.

What am I doing wrong?


Ã,  // script for hotspot4: Look at hotspot
int cool_thing;
if (cool_thing == 0) {
Ã,  Display("The TV is off.");
}
if (cool_thing == 1) {
Ã,  Display("You can see your reflection.");
}
if (cool_thing == 2) {
Ã,  Display("Your reflection is sexy!");
}
if (cool_thing == 3) {
Ã,  Display("You can't see anything else.");
}
if (cool_thing < 3) {
Ã,  cool_thing ++;
}

LordHart

You had the wrong thingy at the end (edit in red):

// script for hotspot4: Look at hotspot
int cool_thing;
if (cool_thing == 0) {
  Display("The TV is off.");
}
if (cool_thing == 1) {
  Display("You can see your reflection.");
}
if (cool_thing == 2) {
  Display("Your reflection is sexy!");
}
if (cool_thing == 3) {
  Display("You can't see anything else.");
}
if (cool_thing < 3) {
  cool_thing +=;
}

ScottDoom

#2
I tried what you gave me, and I get an error.

But I think you meant: cool_thing += 1
I tried that to, and it's the same as cool_thing ++ (in other words, it doesn't work.)

Gilbert

#3
Actually his one was correct, your's not.

cool_thing++;
is equivalent to
cool_thing +=1; // you missed out the one
or
cool_thing=cool_thing+1;

The reason the code won't work was because the variable cool_thing was declared within the function, it will be reinitialized to 0 everytimes that interaction is called.

You have to declare it outside of the function, just move that "int cool_thing" line outside to the top of that room's script and it should work.

EDIT:
heh yea scott you replied faster than me (so my first lines were directed at Ultimo ;) ).

ScottDoom

int cool_thing;
  // script for hotspot4: Look at hotspot
if (cool_thing == 0) {
  Display("The TV is off.");
}
if (cool_thing == 1) {
  Display("You can see your reflection.");
}
if (cool_thing == 2) {
  Display("Your reflection is sexy!");
}
if (cool_thing == 3) {
  Display("You can't see anything else.");
}
if (cool_thing < 3) {
  cool_thing +=1;
}


I did that. It's still not working. Do I need to separate the "int cool_thing;" line from the rest with } or something?

Gilbert

No, by outside of the function you cant type it in by just clicking the "Edit script..." button in the interaction menu, as everything you entered there will be inside that function. you need to click the "Edit Script" icon in the room editing screen (the icon with braces { }, NOT within the interaction menu). Just put the line on top of the whole room script.

ScottDoom

#6
Woohoo! It works. Thanks for the help.

Now I'm going to attempt an intro that has the character say something, then move to the next room, and say something else. Wheee!

One more question though...

Does this mean in every room I can have an integer named (if I wanted to) cool_thing? And how would I make a global integer... GlobalInt? Do I just put that in the starting room? (Sorry this is basic stuff, but I didn't see it in the tutorial so far... maybe it's later on...)

Gilbert

Depends on whether you want to do similar things in other rooms, if you want to use a variable for other thing in other room, you need to declare one in that room too.

I think the following are placed somewhere in the manual and tutorials but while we're on the topic (and I'm just too lazy to search for them), I'll sum it up here:
- Variables declared in a script is initially local to that script only (ie. if you define a variable called blah in a room's script, it's local to that room script only; even if you define a variable in the global script, it's by default local to the global script only). So you can have two variables having the same name in 2 rooms, but are independent of each other.
- As all variables declared in the global script are by default local to the global script only, you have at least two ways to make variables accessible to other room scripts:
1) Use the GlobalInt's, there're 500 globalints (0 thru 499) already provided for you, which are accessible anywhere in scripts using the functions GetGlobalInt() and SetGlobalInt() (you can read the manual for more info). The drawback was that you MUST use these two functions to access them (ie. you cant type directly some "cool" thing like globalint1++ but have to type SetGlobalInt(1,GetGlobalInt(1)+1) instead say for example).
2) After declaring a variable in the global script, export it and then import it back in a room script.
For example:
Global Script
int blah;
export blah;

Room Script
import blah;

You can then access that variable directly in that room, you can read more about it from Text script functions --> Script language keywords of the ags manual.


ScottDoom

Thanks for the info. I'm glad I'm actually understanding this now. I'm trying to script out everything I'll want to do in the game I'm planning to make before I actually start making graphics for the game.

The only other experience I've had with scripting was with DragonSpeak from the game Furcadia. It was used to program bots (sort of like characters in AGS, which would respond to different keywords when you spoke to them), and to program different functions in worlds you created (such as making a door swing open and shut, along with a sound effect, as you walked through it). I liked it a lot, and programmed a whole pirate ship I created by myself.

AGS scripting is pretty much the same as DragonSpeak, except with a whole lot more commands and variables.

Gilbert

Well AGS just adapted C style scripting (with some small exceptions), so it'd be easy to pick up if you have some experience with C-programming, I think DragonSpeak used similar scripting style.

SMF spam blocked by CleanTalk