Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 global variables
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sashman




PostPosted: Sun Jun 19, 2005 8:19 pm   Post subject: global variables

i've been trying to find a way to create a variable that can be shared over different files, and so far i've been unsuccessful. The only thing that i found was:

external var variable : int

but when i try to save my file, it doesn't accept it, it just says that it's not supported. anyone know anything about this?

thanks for your time
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Jun 19, 2005 8:37 pm   Post subject: (No subject)

external is not what you want.
It all depends how you are linking your programs. If you are using include, then just put the variables into either the main program or the program where they are used. If you are making units and importing them, well, you should declare your variables within the monitor/module/class.
sashman




PostPosted: Sun Jun 19, 2005 8:48 pm   Post subject: (No subject)

i just wanted to share one variable between two simple programs that are turing files, but will be saved as .exe.

i have a main menu program for a game i'm creating, where you can click on "new game", in which case it'll execute an cutscene then the game program. Or you can click on "select scene" in which case it will only play the actual game (which is .exe).

not sure if u really understand that. but thanks
Delos




PostPosted: Sun Jun 19, 2005 8:52 pm   Post subject: (No subject)

If you're looking to have various .exe's executed from a single main menu, then you might want to look into Sys.Exec() instead.
Sharing a variable, as you've described, is not the best idea. You can declare a bunch of variables in one file, and then include them in another file. This will give you your desired effect.
However, it is more advantageous(sp?) and efficient to set your programmes us in module or class format, and pass variable values between programmes.
sashman




PostPosted: Sun Jun 19, 2005 8:55 pm   Post subject: (No subject)

ok i think i can make this sound better.

when i click something in my main program, my variable newgame will be set to 1.
then my external file is executed but it will only play the cutscene if newgame is equal to 1 (to indicate a new game). Otherwise, newgame is equal to 0, which means you only play the game.

The actual cutscene is located in the game.exe file (that's what it'll be called), and will only execute the cutscene if newgame equals one.

thanks
sorry for any confusion
sashman




PostPosted: Sun Jun 19, 2005 8:59 pm   Post subject: (No subject)

my skills in programming are very limitted, so i dont' really know how to set my program into modules or classes (don't really know what they are).

but how do you do the "include" thing that you're talkinga about?
Delos




PostPosted: Sun Jun 19, 2005 9:09 pm   Post subject: (No subject)

Check in the Tutorials section under 'Modules'. Even if you're not going to use modules, the tutorial will show you how to use the command.

As for your variable use, there are easier ways of doing it. My personal favourite was to create a 'key-file' that would be created when the same condition that sets your variable to 1...
So...instead of:
Turing:

if newGameSelected then
   newgame := 1
end if
%...
%other programme now:
if newgame = 1 then
% run...
end if


reaplace with:

Turing:

if newGameSelected then
   % create a file with the name, say, "cache.tmp"

   % could be *anything* you want...could even contain
   % text to be more specific about what the next programme
   % should do
end if

%...
% next programme

if File.Exists ("cache.tmp") then
% run...
% or you could open the file, check it and see if there are additional
% paramteres to consider!
end if


Check the Tutorials on how to make Files if you don't already know. Hope you understood all of that.
sashman




PostPosted: Sun Jun 19, 2005 9:22 pm   Post subject: (No subject)

sweet! thanks a lot for the help!
Sponsor
Sponsor
Sponsor
sponsor
StarGateSG-1




PostPosted: Tue Jun 21, 2005 11:42 am   Post subject: (No subject)

Why would you have more than one .exe file, When the program complies it grabs all included files aswell. It would be to bulky to have more then one, just use 1 big one.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: