Change Interaction

Started by , Sat 05/02/2005 20:10:16

Previous topic - Next topic

Guest

Say i use item A on hotspot B. How do i edit it to display a different message if i do it again?

LeChuck

I do it like this:


   if (GetGlobalInt(1)==0) {
      // Add code for first interaction
      SetGlobalInt(1, 1);
      }
   else {
     // Add code for second interaction
   }

Guest


Ashen

I think LeChuck means to use variables - that's the most logical way, anyway.
The example assumes you're using scripting, in which case you could just copy that code into the Use Inventory on hotspot interaction. If you're using the interaction editor, however, you need to:

1. Open the Interaction editor, and add a new action under Use inventory on hotspot - the 'Conditional - If inventory item was used', with the item number set to the number of item A.

2. Add an action under this - 'Conditional - If varaibale is set to a certain value'. Click the 'Change' button next to 'Variable:0', then the 'Edit Variables' button. Create a new variable - you can call it whatever you like, but I'll call it 'beendone'.

3. Set the conditonal to run if 'beendone' is set to 0. Now add whatever you want to happen the first time you use item A on the hotspot. Finish it off with a 'Game - Set variable' command that changes 'beendone' to 1, and a 'Stop running more commands' command.

4. Add another 'Conditional - If varaibale is set to a certain value', this one set to run if 'beendone' is set to 1. Add whatever you want to happen the second time you use the item.

5. If you want to have something different happen the 3rd, 4th, 5th, etc times, just use 'Game - Set variable' and 'Conditional - If varaibale is set to a certain value' as needed.

Overall it should look something like:

Use inventory on hotspot
  - Conditional - If inventory item was used (ITEMA)
    - Conditional - If varaibale is set to a certain value (beendone, 0)
      //whatever you want
      Game - Set variable value (beendone, 1)
      Stop running more commands
    - Conditional - If variable is set to certain value (beendone, 1)

If I haven't explained something properly, just look variables up in the manual, it should all be there.
I know what you're thinking ... Don't think that.

LeChuck

Quote from: Guest on Sat 05/02/2005 23:30:03
???PLz simplify ???

It would be alot simpler if you actually asked a question... If you have a bare minimum of programming knowledge, you should know what the if / else stuff does.

GetGlobalInt and SetGlobalInt, this is probably the part you don't understand... In AGS you have what's called global variables, and by default all these variables are set to 0. You can use whichever one of these you want anywhere in your code. In my example it uses the global variable 1, which by default has the value 0. A global variable can only have the values 0 or 1 - think of it as off and on.

Code: ags

Ã,  Ã, if (GetGlobalInt(1)==0) { // This part checks if the action has been executed before. If global variable 1 has the value 0, do this.
Ã,  Ã,  Ã,  // Add code for first interaction
Ã,  Ã,  Ã,  SetGlobalInt(1, 1); // This part tells the script that the first interaction has happened, hence we change global variable 1's value to 1.
Ã,  Ã,  Ã,  }
Ã,  Ã, else { // This part is what is run if the first interaction has happened, ergo global variable 1 HAS been changed to 1.
Ã,  Ã,  Ã, // Add code for second interaction
Ã,  Ã, }


I tried explaining it closer in the code above. Of course, if you prefer not to script, you can do what Ashen suggested.

Proskrito

Quote from: LeChuck on Sat 05/02/2005 23:52:38
A global variable can only have the values 0 or 1 - think of it as off and on.
the 'GlobalInts' are integer type variables as the name implies, so can have many more values than 0 or 1 : )

SMF spam blocked by CleanTalk