manual tutorial technical "if" counter problem

Started by , Fri 10/02/2006 17:58:58

Previous topic - Next topic

adacadadacad

 :(

Im terribly new at AGS and scripting. I was reading the manual on scripting and found most of it easy to understand. It didnt define "Instances", or "handlers", but no worries. I copied-and-pasted a section of the code in the scripting tutorial into a new game to see how it would work.

Code: ags
// script for hotspot1: LOOK AT HOTSPOT     
  if (my_counter == 0) {
    Display("You see a bookshelf.");
  }
  if (my_counter == 1) {
    Display("Looking closer, you see a book called Hamlet.");  
  }
  if (my_counter == 2) {
    Display("There is also a book called Harry Potter.");
  }
  if (my_counter == 3) {
    Display("There is nothing else of interest on the shelf.");  
  }
  if (my_counter < 3) {
    my_counter += 1;
  }


This I put in the room script area. I renamed the hotspot to fit the code, saved and tested.

I got an error saying: "Parse error. Unexpected "if" "

What am I doing wrong?

Im having trouble understanding variables.

Wretched

#1
You need to put the code inside a function, not just anywhere in the script.

Use the interaction editor to setup a 'Run Script' function to call a script when the hotspot is looked at, then place the code in there.

However you will also need to put an

int my_counter;

line in the room script file at the top.

The code outside the functions gets executed when the room is loaded, So this will set the my_counter variable, (initially to 0),
Then your code will only be run when the hotspot lookat function is called.

adacadadacad


SMF spam blocked by CleanTalk