Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FinalSin on Tue 29/06/2004 09:33:46

Title: Scripting Problems With Integers/Inventory Items (SOLVED)
Post by: FinalSin on Tue 29/06/2004 09:33:46
Okey doke, just started scripting, and doing well until I tried to get this script to run for one of my inventory items:

#sectionstart inventory6_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function inventory6_a() {
// script for inventory6: Look at inventory itemÃ,  Ã, 
Ã,  if (my_counter == 0) {
Ã,  Ã,  Display("Mufkin's big book of Secret Bookcase Passageways");
Ã,  }
Ã,  if (my_counter == 1) {
Ã,  Ã,  Display("Chapter 1 - Holes in bookcases often reveal passagewqays if the right book is put into them.");Ã, 
Ã,  }
Ã,  if (my_counter == 2) {
Ã,  Ã,  Display("Chapter 2 - Books are often cunningly titled to suggest their secret use.");
Ã,  }
Ã,  if (my_counter == 3) {
Ã,  Ã,  Display("Funny, that's all it says...");Ã, 
Ã,  }
Ã,  if (my_counter < 3) {
Ã,  Ã,  my_counter += 1;
Ã,  }Ã, 
}


then, I set the constant for my_counter at the top of the script. Waaay up the top around this bit:


#sectionstart game_startÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
Ã,  int my_counter
Ã,  }
Ã,  // called when the game starts, before the first room is loaded


No doubt I am doing something wrong - numerous messages appear, but the most common one is 'unexpected "}"'

any ideas?

Title: Re: Basic Scripting Problems... Again...
Post by: jetxl on Tue 29/06/2004 09:42:01
first don't forget the ;
try declaring int my_counter on line 1.
Title: Re: Basic Scripting Problems... Again...
Post by: FinalSin on Tue 29/06/2004 09:47:02
Okay, that half worked. Now, for some reason, it says that 'nested functions are not supported' on a line I haven't edited:

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
Title: Re: Scripting Problems With Integers/Inventory Items
Post by: jetxl on Tue 29/06/2004 09:54:34
maybe you forgot a }
Title: Re: Scripting Problems With Integers/Inventory Items
Post by: FinalSin on Tue 29/06/2004 10:05:21
It says I've forgotten a closing brace, but I can't see where to put it...
Title: Re: Scripting Problems With Integers/Inventory Items
Post by: Gilbert on Tue 29/06/2004 10:07:55
Can you post your whole script here for us to see?
Title: Re: Scripting Problems With Integers/Inventory Items
Post by: FinalSin on Tue 29/06/2004 17:16:44
Alright, I think the main problem is this:

In the 'Examine Inventory' script I have this:


#sectionstart inventory6_a  // DO NOT EDIT OR REMOVE THIS LINE
function inventory6_a() {
  // script for inventory6: Look at inventory item

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;
  }
}
#sectionend inventory6_a  // DO NOT EDIT OR REMOVE THIS LINE


And I need to insert this somewhere in the global script:
int my_counter;
But whereever I place it it creates problems. If I put it in the inventory part of the globalscript, it just resets to 0 every time the script is run, just like it says in the tutorial. Putting it anywhere else just means that it doesn't understand what counter I'm talking about.

any help?
Title: Re: Scripting Problems With Integers/Inventory Items
Post by: FinalSin on Tue 29/06/2004 17:20:10
Solved! Thankyou very much, I have learnt much!