Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Cannot get globals to be "globals"  (Read 2531 times)

0 Members and 1 Guest are viewing this topic.

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Cannot get globals to be "globals"
« on: April 01, 2009, 12:42:25 AM »

Later

I think I have worked it out it seems you have use the global prefix prior to using the variable in other scripts, that's fine, but my thinking was that if you re-used the global prefix you would re-initialise the variable - perhaps you can confirm these assumptions for me.


Probably doing something very obvious incorrectly here.  I am trying to use globals for games state, and they don't appear to work, I have looked at the thing a number of times, and even used the globals that are automatically initialised, but they don't seem to be visible to other procedures

this is the debug list

00:21: Compiling script 'scenes\greendale\scr\pat.script'...
00:21:   Error@line 26: Variable 'Stategreendale' is referenced but not defined
00:21: Compiling script 'scenes\greendale\scr\pat.script'...
00:21:   Error@line 62: Variable 'SpeechTrigger' is referenced but not defined
00:21: Compiling script 'scenes\greendale\scr\cu_background.script'...
00:21:   Error@line 4: Variable 'SpeechTrigger' is referenced but not defined
00:21:
00:21: Shutting down...
00:21: Shutting down scripting engine

and the offending code is in three scripts, the two globals Stategreendale ( system generated) and SpeechTrigger are initialised in screen_init.script.

global Stategreendale;
global SpeechTrigger = 0;

in the script oat.script both are assigned values

Stategreendale.Visited = true;   - line 26
 SpeechTrigger = 1;  - line 62


in the script cu_background.script

if (SpeechTrigger ==1);

is there some switch I need to set for globals to work ?




« Last Edit: April 01, 2009, 01:09:54 AM by eborr »
Logged

Akusa

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 46
    • View Profile
Re: Cannot get globals to be "globals"
« Reply #1 on: April 01, 2009, 01:30:24 AM »

HA NOBODY EXSPECTS THE GLOBAL VARIABLE ERROR!
You have to initalize the global variable in every script it uses. So it wont work to initalize it in scene_init.script if you want to use the variable in pat.script.

So here are three solutions:
- you initalize every global variable in all your scripts. (bad)
- you use the base.inc file for all globals you want to use because its automaticly included.
- you use a mix of both, for example the most used global variables in the base.con and the rest in your scripts itself.
« Last Edit: April 01, 2009, 11:32:25 AM by Akusa »
Logged
 

Page created in 0.044 seconds with 19 queries.