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.

FPSC Classic Scripts / Global Variable Question

Author
Message
Mriganka
3
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 13th Oct 2017 18:39
In almost all of my scripts I use global variables. So, if I use those scripts again in the next level will there be any conflict? Or should I make a script that initializes the global variables in a go, and the other scripts just use them? That would be the easier way to go, but will I encounter any problems when the player enters another level?
Tomik18
FPSC Reloaded TGC Backer
8
Years of Service
User Offline
Joined: 8th May 2009
Location: Slovakia
Posted: 13th Oct 2017 23:39
in the script folder I would create a folder for each level, such as "level1" "level2" and copy the scripts into these folders and load them from each folder for that level
My PC specs: AMD FX 4300 3,80Ghz
8 GB RAM
GIGABYTE R9 280 Ultra Durable VGA 3GB
ncmako
5
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 14th Oct 2017 13:54
Mriganka
Yes and No Global variables reset to 0 from one level to another, so if you need to retain the value from previous level
you will need to create a script in the beginning to set your variable to the value you want/need.
But.... "dimvar" retains their value from one level to another ( worth looking into as a choice )

Here is a link to BlackFox & Flatlander's explanation in the use of "Global & Local" variables..
https://forum.thegamecreators.com/thread/192148 Scroll down a bit until you see "Using Global Variables"
It explains in detail clearly.
My games never have bugs. They just develop random features..
Lots and lots of random features...
Mriganka
3
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 11th Nov 2017 15:20
Sorry, I forgot this thread even existed. ANother question from me is - if I initialize the same variable (variable with the same name) again and again everytime I enter a level, will it be problematic?
ncmako
5
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 11th Nov 2017 21:09
Mriganka I wouldn't think so, that's what they are meant to do. I haven't had problems with
multiple variables & names. If you are using one a lot everywhere, maybe keep the script as short
as possible as not to cause problems.
My games never have bugs. They just develop random features..
Lots and lots of random features...
Mriganka
3
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 12th Nov 2017 04:11
Actually I am initializing a few variables that will be used in all the levels. They are global variables. But I could have a separate file initializing those variables or initialize them again again. I cannot seem to think if I would get any errors.
ncmako
5
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 12th Nov 2017 14:05
Mriganks I almost forgot about this command resetglobalsonreload=0 or 1 "This defines whether or not the default global variables (numbered
0 to 99) are reset at the start of each level"
I recall from sometime ago when this command was put in, members wanted the "Globalvar" to carry over.

***the Syntax list describes these commands as ***
Dimvar's retain their value from one level to another, but Global variables reset to 0 at the transition from one level to another.
So if you use the "globalvar" command and need that value to remain into the next level, you will need to create a script in the beginning to set your variable(s) to the value(s) you need

I think the Syntax list wasn't updated when the new "resetglobalsonreload=x" was inserted I just guessing here. But it seams to me with this activated
Globalvar's will carry over without extra scripting ???
My games never have bugs. They just develop random features..
Lots and lots of random features...
Mriganka
3
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 12th Nov 2017 17:21
I could use the reset command. But my main confusion is with initializing the same global variable again and again in the scripts for each level. And from what I have learnt the global variables are carried over from one level to another. It's just that in my scripts the global variables will be initialized again and again as the levels change. But from that new game on steam featuring my scripts, it seems to work. Will give a try out to them later to see if it actually does.

Login to post a reply

Server time is: 2017-11-25 07:29:44
Your offset time is: 2017-11-25 07:29:44