Scripting Problems With Integers/Inventory Items (SOLVED)

Started by FinalSin, Tue 29/06/2004 09:33:46

Previous topic - Next topic

FinalSin

Okey doke, just started scripting, and doing well until I tried to get this script to run for one of my inventory items:

Code: ags
#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:

Code: ags

#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?

The Blue Casket

jetxl

first don't forget the ;
try declaring int my_counter on line 1.

FinalSin

Okay, that half worked. Now, for some reason, it says that 'nested functions are not supported' on a line I haven't edited:

Code: ags
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
The Blue Casket

jetxl


FinalSin

It says I've forgotten a closing brace, but I can't see where to put it...
The Blue Casket

Gilbert

Can you post your whole script here for us to see?

FinalSin

Alright, I think the main problem is this:

In the 'Examine Inventory' script I have this:

Code: ags

#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:
Code: ags
 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?
The Blue Casket

FinalSin

Solved! Thankyou very much, I have learnt much!
The Blue Casket

SMF spam blocked by CleanTalk