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
10
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
15
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
12
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
10
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
12
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
10
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
12
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
10
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.
Stealth Sin
11
Years of Service
User Offline
Joined: 18th Nov 2013
Location:
Posted: 25th Dec 2017 01:39
Quote: " But from that new game on steam featuring my scripts"


Wait? you can add FPSC games on steam without greenlight or do you have green light?
Anthony Gonzales
Mriganka
10
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 25th Dec 2017 05:44
Lol. Greenlight is dead. Now you have to pay a sum to publish your games on Steam.
BlackFox
FPSC Master
16
Years of Service
User Offline
Joined: 5th May 2008
Location: Knight to Queens Bishop 3
Posted: 3rd Jan 2018 00:45
Quote: "****As of r531 (FPSC v1.19), an action "resetglobalsonload" was added to the source. This changed the behavior of global variable values. By default, the reset flag is set to 0, and if the command "resetglobalsonload=1" was used, then globals were reset to 0 before loading a saved game. This allowed developers to have control on the global variable reset."


Unless the above has changed...
There\'s no problem that can\'t be solved without applying a little scripting.
Mriganka
10
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 3rd Jan 2018 04:41
Thank you for that. I have made some scripts heavily dependent on global variables. I just thought of making a separate script that declares all of the variables first, so that I don't have to declare the variables again every time a new level loads.
BlackFox
FPSC Master
16
Years of Service
User Offline
Joined: 5th May 2008
Location: Knight to Queens Bishop 3
Posted: 3rd Jan 2018 05:45
No problem. I always make an init script in the beginning to state and set my variables, and each level I had initializes those variables to the values they need to be at in order to proceed into that level. I did this method because A) I work in v1.17 and the command "resetglobalsonload" was not in my source (nor did I add it even though I did port water and other features into my source); B) it allowed for any issue if the player decided to save before finishing a level to be able to load and continue.

Although later in coding my source I created a different approach to variables where I have mine written to a text file and the source now reads that file at each level to ensure values are correct which solved the issue of variables being reset, but again that is in my version and I do not know what state it was at when it finally stopped being developed. So in the general case, try an init script at the beginning and see if that works. If the values do carry for you throughout, then you are set. If not, then you may need to create an init for each level to get them to your needed values.
There\'s no problem that can\'t be solved without applying a little scripting.
Mriganka
10
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 4th Jan 2018 05:59
The variables seem to carry on through with the init script. But I have thought of making the whole game episodic (seperate EXEs), hence the init script will not be needed, and I will have way more control over elements in each level.

Login to post a reply

Server time is: 2024-11-23 09:26:33
Your offset time is: 2024-11-23 09:26:33