Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / global variable ?

Author
Message
Alain91
12
Years of Service
User Offline
Joined: 20th Aug 2011
Location: France
Posted: 1st Sep 2011 16:39
Hello,

Please could you explain how to set a global variable ?

I want to use a variable in several modules but it seems that variables are 'local' to their own modules ?...

Thanks for your help,
Alain
Mike Johnson
TGC Developer
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 1st Sep 2011 16:43
Add any globals into your main.agc file and they can be used in any included files.
Alain91
12
Years of Service
User Offline
Joined: 20th Aug 2011
Location: France
Posted: 1st Sep 2011 17:11
Thanks for your answer, but it doesn't seems to work (with me )

my example :


main code :


the "test.agc"



What am I missing please ?

regards,
Alain
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 1st Sep 2011 22:40
Just a guess, but the problem might be in your PRINT statements.

Try changing them to:

print (str(myValues[1]))
print (str(myValues[2]))
print (str(myValues[3]))

The Print statement is looking for string values, which your array is not, so you need to convert them to a string using the str() command.

Hope that was it.

Thanks
JHA
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 1st Sep 2011 23:09
The type casting to string is not the problem here. The problem is that, when you include a new file, the code that it is in there, outside any function or subroutine, won't be executed like if they were in your main file.

If you add them to a function (or subroutine) in your test.agc file, and call this function at some point in your main.agc, then it will work.

Better show you than explain:

test.agc:



main.agc:




You'll notice that in the main.agc, before the main loop starts, I'm calling the function, so the values are correctly set.

This is based on my observations, so maybe some TGC experts can confirm it


Cheers

----------
Paulo
http://www.mobilecreators.com
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 1st Sep 2011 23:52
Now that I look at it again, I do see the problem.

The values are never being set, because he is never calling a sub or function to actually set them.

DOH!! I should have seen that the first time.....

Good catch MobileCreator!!
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 2nd Sep 2011 02:01 Edited at: 2nd Sep 2011 03:14
Quote: "The Print statement is looking for string values, which your array is not, so you need to convert them to a string using the str() command."


That was my first thought too JHA

Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 2nd Sep 2011 10:18
There's no need to change them into strings. I use Print(array[0].thing) all the time and it prints integer and float values just fine.

Login to post a reply

Server time is: 2024-03-28 16:00:31
Your offset time is: 2024-03-28 16:00:31