** I apologize for a lengthy novel, but we are a bit stumped on an issue with a game development loading a saved game and global variable values. I hope I have been as descriptive as possible. **
My wife and I are working on a SciFi development and have written our own script to deal with various keys that are used throughout the game. One key is used for our inventory, another for objectives, missions, etc. In this script we have used the "globalvar" action and have assigned variables to different items. For example:
globalvar=1 is for PADD1B (assigned the key V)
globalvar=2 is for PADD2G (assigned the key B)
globalvar=3 is for PADD3R (assigned the key N)
globalvar=4 is for PADD4M (assigned the key M)
globalvar=5 is for Objectives (assigned the key O)
globalvar=6 is for Inventory (assigned the key I)
globalvar=7 is to toggle the keys On/OFF (meaning at some points in the game, we have scripts that set the value of globalvar=7 to 0 which deactivates the key and the player can't assess that item; used during briefings, conversations, etc)
In the start of the game, the player is in their quarters. Their first objective is to collect their gear (which consists of the 4 PADDS). If they go to leave the room, a hud comes up to tell them they need to collect their gear first and the door does not open. As they pick up each PADD, the pickup script will increase the value of the global variable assigned to that item. For example, here is the script that is used when picking up the PADD1B:
;Artificial Intelligence Script
;Header
desc = Level 1 Collect Info PADD
;Triggers
:state=0:hudreset,hudx=50,hudy=15,hudimagefine=languagebank\english\gamecore\MK-TEK\Imperium_DF\Huds\imp_df_l01_padd1b_pickup.tga,hudname=l01_padd1b_pickup,hudhide=1,hudmake=display
:state=0:hudreset,hudx=12.5,hudy=10,hudimagefine=languagebank\english\gamecore\MK-TEK\Imperium_DF\Huds\imp_df_io_completed.tga,hudname=l01_io01_completed,hudhide=1,hudmake=display
:state=0:state=10
:state=10,plrdistwithin=50:hudshow=l01_padd1b_pickup,state=20
:state=20,plrdistfurther=60:hudunshow=l01_padd1b_pickup,state=20,state=10
:state=20,scancodekeypressed=20:hudunshow=l01_padd1b_pickup,playertake,coloff,activateifused=1,hudshow=l01_io01_completed,hudfadeout=l01_io01_completed,state=30
:state=30:globalvar=1,incvar=1
:state=30:state=31
:state=31:globalvar=5,incvar=1
:state=31:state=32
:state=32:none
;End of Script
So in the above script, the player picks up the blue PADD, the global variable for the blue PADD (1) increases by a value of 1. The global variable for the objectives (5) also increases by a value of 1. This is the same with the other three PADDs, except the global variable for the other three PADDs are 2, 3, 4 (as shown in the first code block); they also increase by a value of 1 and the objective global variable value increases by 1 for each PADD picked up. With 4 PADDs to be collected, the objective global variable (5) has a value of 4, and when the player presses O to show their objectives, a checkmark appears to show that objective (Collect your gear) is done. The player can now leave the room, since the door script checks the global variables (1-4) and if the value of each is equal to 1 (this means the player has picked up the item), the door opens for them and they can continue. In other words, global variable (1-4) will have a value of 1 for each since those items were picked up.
By playing the entire level, everything works as it should. As each objective is completed, a checkmark appears by that objective. We have scripts throughout that check global variable values and if certain global variable values are not where they should be, the player can't continue on. For example, there is an access door that will open ONLY if the objective global variable (5) value is equal to 6. If not, a hud comes up to tell the player an objective has not been completed.
Here is the issue...
When we go to load a saved game, the game loads but our variable values are not retained. For example, I collect the 4 PADDs and leave my quarters. I press O to view my objectives and I see a checkmark on the objective (#1. Collect your gear) which means it has been done. I save my game (press Esc, click Save Game, select slot), and the game is saved. When I load that saved game slot, I press O and the checkmark is not there, which tells me that the global variable for objectives (5) is not equal to 4. As I continue on, other items and such throughout the game are not working since my global variables values are not where they should be (I hope that made sense).
We are wondering if either: A)We have used the syntax incorrectly, although it works as it should from start to finish; B)Is it the init script during the load that resets the global variable values to 0 (:state=1 lines, global variables 1-6)?
ADDITIONAL:
I had a theory that when the save game is loading, that init script is the cause, so I had tried a different method. I took the :state=1 lines with the global variables 1-6 out, put them in their own script and assigned to a trigger in the beginning of the level where the player starts (the player passed through the trigger and the script does the variable values). I collected the PADDs, checked my objectives and saw the checkmark, saved the game. When I loaded that saved game, there was no checkmark on the completed objective and that told me that was not the issue.
I'm certain it is something I've overlooked, but I've looked at this so many times that I'm getting more gray hair than what I have already LOL. If anyone has a suggestion, idea, or spots my error, we would really appreciate the input.
ADDITIONAL2:
This is being developed in FPSC x9 v1.17.011. No mods- strictly vanilla.
:: Issue Resolved ::
- BlackFox
The function of good software is to make the complex appear to be simple.