|
Bartiloux Desmoulins
Think Kink? Think Bart!
Join date: 27 Sep 2005
Posts: 121
|
05-26-2007 11:52
Okay. I've been programming in various languages for the past 25 years. I've read the WIKI on the topic and thought I understood what I read but, obviously, I'm missing something. Am I correct in saying a global variable is not a constant but, rather, is a variable whose value you can both reference AND CHANGE in any subsequent "procedure" you write within your script? I have a script that reads a note card. At the top of the script, outside any procedure, I declare a global variable gLine as an integer to keep up with what line of the note card I'm reading. Within the Entry state I set it equal to zero and go through the motions (via wiki-provided code) to read two lines of my note card. The problem is this. I want to re-read the card if I detect the user has changed the note card or if they type "RESET" which is a keyword for which I have set up a listen trap. Initially, the script reads the note card just fine. When inside my reset code, however, when I try to set gLine back equal to zero to go through the re-reading of the note card, I get a compile error saying that gLine is not defined within the scope. The variable is global and, since the "note card read" procedure had no trouble incrementing its value by one with a ++gLine, I fail to see what's any different by my setting it equal to zero in my reset routine. Help! I'm rapidly losing what little hair I have left!! Thanks, Bartiloux Desmoulins
|
|
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
|
05-26-2007 12:05
Global variables are just like you expect: defined outside states and functions, and accessible and changeable to them all (within a script).
Want to post the code?
|
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
05-26-2007 12:11
It would be helpful to see some code, but a global variable is defined outside of any state: Thus: integer gLine; default { state_entry() { gLine = 0; } } ...not... default { state_entry() { integer gLine; gLine = 0; } } ...or... default { state_entry() { integer gLine = 0; } } ...in the later two examples gLine's 'scrope' is state_entry in the default state. Just to confuse matters gLine could be both global and local: integer gLine; default { state_entry() { integer gLine = 0; } } In this case gLine in state_entry in the default state is not the global gLine, but the global gLine can still persists elsewhere.  Basically, the 'scope' of a variable is determined according to where it is declared. I hope this helps. And I wish the tags could be fixed! :p
|
|
Bartiloux Desmoulins
Think Kink? Think Bart!
Join date: 27 Sep 2005
Posts: 121
|
05-26-2007 13:07
One follow-up question if you will indulge me...
Does the "Official Scriptors Ethics & Code of Conducts Manual" require scriptors, from newbies to experts, to confess to making stupid mistakes that, in turn, cause them to post to the forums, wasting the valuable time of their friends, acquaintences, and colleagues? Well, if it does, suffice it to say that, regardless of whether a variable is local or global, the following will always remain true... gline != gLine; In my defense, may I simply state that I hate "Camel Case" code??? *lol* Thanks to those who replied and I offer my humblest apologies for wasting your time. Bartiloux Desmoulins
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
05-26-2007 13:20
dont worry it happens if you want nuts go over to the textures forum where theres always a "um how do i make an alpha" question litterly right below the umpteen page sticky that gives detailed step by step directions for 4 or 5 different software packages 
|
|
Sterling Whitcroft
Registered User
Join date: 2 Jul 2006
Posts: 678
|
05-27-2007 05:33
OH! Thanks for the tip,Osgeld! I'd been wondering how to make an alpha! 
|