Using Variables

Started by Shadow, Tue 16/12/2003 17:34:27

Previous topic - Next topic

Shadow

I wanted to use a Variable (lets say its name is "Hello"), if it is set to 1 a action should be performed. So I defined the Variable at the top of the Global Script, right after "//main global script file", with int Hello; .
Then I put a import command for the variable into the Scriptheader: "import int Hello" .
Then saved the game, and no Problems. But when I tried to Test the game, there comes the Error Message:
Error: Unable to create local script: Runtime error: unresolved import 'Hello'
What have I done wrong????????????????????????????????????????????
When I made it with the point and click GUI of AGS, it worked once, but when I tried it a secound time, it didn't work anymore (still wonder about this).
Is it possible, that AGS gets more and more bugs, the bigger the game grows????? At the beginning there were no problems, but now there appear more and more things, that aren't possible (it plays wrong anymations, it dosen't change the Characterview, it plays the music althoug it wasn't told to .....)

SSH

It's possible that YOUR code gets more bugs the larger your game grows, yes.

It has already been established in other discussions that CJ is infallible and thus AGS has no bugs.

Seriously, though, you even seem confused in your post about the variable name: is it Hello or Hallo? First thing is to double check that you spelt it the same way in both the global script and header.
12

Isegrim

Are you sure you export-ed the variable? When you want to import a variable, you have to export it from the main script first.
This post was generated automatically and therefore bears no signature.

juncmodule

#3
Quote
// Start of Global Script (MAKE SURE IT IS THE BEGINNING
int has_book=0;

//end of Global Script (MAKE SURE IT IS THE END)
export has_book;

//Header Script (you can put it anywhere in here)
import int has_book;

A few things.

No.
The script does not get buggy the bigger it gets.
Your brain does ;D.

You really need to keep track of everything, comment your code to death.

When you have something that doesn't work the way you think it should, do a display message in the middle of it to ensure that it is executing. There are tricks to checking your code. You must be very clean and organised.

SSH pointed out something very important. The smallest misplaced letter will screw everything up.

I had a little trouble with defining global variables myself. I think there are a few things in the help file that need to be a little bit clearer and more accessable. I'm not sure if this is one of those things, but it may be. :P

good luck,
-junc

EDIT: I missed one...

The did it once and it worked fine, again and it didn't thing.

AGS seems to do some funny stuff. I would always test things twice. Especially when you are working with new variables. I think that it needs to compile the scripts and run through them in order to work. I am always left with the feeling that I need to tell it that I added a new variable before it will work. So, one compile and run to set the variable in, a second to test it. I know this isn't really the way it works, but it is a good safegaurd anyway.

Shadow

That's what I wanted to know, Isegrim. Thanks.
@SSH Yes thats possible, that my code gets more and more bugs :) I wrote Hallo, because in German Hello = Hallo, sorry for that

Shadow

Thanks for the tips Junk, I did a little test, to test my variable and it worked.

SMF spam blocked by CleanTalk