SOLVED: Save rush combo count

Anybody know a example script? I've been exploring the wiki and the forum and I can't find how to save and retrieve the variable between stages, and delete it after every "next"(score screen)
 
I was looking for it but while looking, can I ask something?

Do you want to preserve combo counter through all levels up to next? or do you want to use combo counter for something else?
 
Points are assigned on the score screen based on the maximum combo, so I want to save the maximum value during each series of stages. After the score screen, it would be reset to zero. Thanks!
 
Toranks said:
Points are assigned on the score screen based on the maximum combo, so I want to save the maximum value during each series of stages. After the score screen, it would be reset to zero. Thanks!

Hi Toranks

Maybe this example can help. You will need to use 3 scripts:

1) Script to save max rush counter - used in the file named endlevel.c inside the "scripts" folder
2) Script to load max rush counter  - used in the file named level.c inside the "scripts" folder
3) Script to reset max rush counter  - used in the file named updated.c inside the "scripts" folder

First you will need to create these files if you don't have it, but if you already have the files with more scripts inside, you will need to call them as a individual functions and change the "void main" to any other name, like "void saveMaxRush" and "void loadMaxRush", and call them in a main function named "void main", like this:
Code:
void main()
{
      saveMaxRush();
      script2();
      script3();
      etc...
}

void saveMaxRush()
{//Save max rush counter when the level ends
	void player1 = getplayerproperty(0, "entity"); //IDENTIFY PLAYER 1
	void player2 = getplayerproperty(1, "entity"); //IDENTIFY PLAYER 2
	void player3 = getplayerproperty(2, "entity"); //IDENTIFY PLAYER 3
	void player4 = getplayerproperty(3, "entity"); //IDENTIFY PLAYER 4
	
	if(player1 != NULL()){ //IS PLAYER 1 PLAYING THE GAME??
		setglobalvar("maxRush1", getentityproperty(player1, "rush_tally")); //SAVE CURRENT PLAYER 1 MAX RUSH COUNT
	}
	if(player2 != NULL()){ //IS PLAYER 2 PLAYING THE GAME??
		setglobalvar("maxRush2", getentityproperty(player2, "rush_tally")); //SAVE CURRENT PLAYER 2 MAX RUSH COUNT
	}
	if(player3 != NULL()){ //IS PLAYER 3 PLAYING THE GAME??
		setglobalvar("maxRush3", getentityproperty(player3, "rush_tally")); //SAVE CURRENT PLAYER 3 MAX RUSH COUNT
	}
	if(player4 != NULL()){ //IS PLAYER 4 PLAYING THE GAME??
		setglobalvar("maxRush4", getentityproperty(player4, "rush_tally")); //SAVE CURRENT PLAYER 4 MAX RUSH COUNT
	}
}

If don't have scripts in these files, you can paste all the codes below with no changes.
Check if you have the file script.txt in the data folder, and the command "alwaysupdate 1" inside, otherwise the RESET script will not work.

SAVE MAX RUSH COUNTER, INSIDE THE ENDLEVEL.C FILE
Code:
void main()
{//Save max rush counter when the level ends
	void player1 = getplayerproperty(0, "entity"); //IDENTIFY PLAYER 1
	void player2 = getplayerproperty(1, "entity"); //IDENTIFY PLAYER 2
	void player3 = getplayerproperty(2, "entity"); //IDENTIFY PLAYER 3
	void player4 = getplayerproperty(3, "entity"); //IDENTIFY PLAYER 4
	
	if(player1 != NULL()){ //IS PLAYER 1 PLAYING THE GAME??
		setglobalvar("maxRush1", getentityproperty(player1, "rush_tally")); //SAVE CURRENT PLAYER 1 MAX RUSH COUNT
	}
	if(player2 != NULL()){ //IS PLAYER 2 PLAYING THE GAME??
		setglobalvar("maxRush2", getentityproperty(player2, "rush_tally")); //SAVE CURRENT PLAYER 2 MAX RUSH COUNT
	}
	if(player3 != NULL()){ //IS PLAYER 3 PLAYING THE GAME??
		setglobalvar("maxRush3", getentityproperty(player3, "rush_tally")); //SAVE CURRENT PLAYER 3 MAX RUSH COUNT
	}
	if(player4 != NULL()){ //IS PLAYER 4 PLAYING THE GAME??
		setglobalvar("maxRush4", getentityproperty(player4, "rush_tally")); //SAVE CURRENT PLAYER 4 MAX RUSH COUNT
	}
}

LOAD MAX RUSH COUNTER, INSIDE THE LEVEL.C FILE
Code:
void main()
{//Load saved max rush counter and apply when the level starts
	void player1 = getplayerproperty(0, "entity"); //IDENTIFY PLAYER 1
	void player2 = getplayerproperty(1, "entity"); //IDENTIFY PLAYER 2
	void player3 = getplayerproperty(2, "entity"); //IDENTIFY PLAYER 3
	void player4 = getplayerproperty(3, "entity"); //IDENTIFY PLAYER 4
	
	if(player1 != NULL()){ //IS PLAYER 1 PLAYING THE GAME??
		changeentityproperty(player1, "rush_tally", getglobalvar("maxRush1")); //CHANGE PLAYER 1 MAX RUSH COUNT WITH LOADED VALUE
	}
	if(player2 != NULL()){ //IS PLAYER 2 PLAYING THE GAME??
		changeentityproperty(player2, "rush_tally", getglobalvar("maxRush2")); //CHANGE PLAYER 2 MAX RUSH COUNT WITH LOADED VALUE
	}
	if(player3 != NULL()){ //IS PLAYER 3 PLAYING THE GAME??
		changeentityproperty(player3, "rush_tally", getglobalvar("maxRush3")); //CHANGE PLAYER 3 MAX RUSH COUNT WITH LOADED VALUE
	}
	if(player4 != NULL()){ //IS PLAYER 4 PLAYING THE GAME??
		changeentityproperty(player4, "rush_tally", getglobalvar("maxRush4")); //CHANGE PLAYER 4 MAX RUSH COUNT WITH LOADED VALUE
	}
}

RESET MAX RUSH COUNTER, INSIDE THE UPDATED.C FILE
Code:
void main()
{//Reset max rush counter in "Stage Complete" screen
	if(openborvariant("in_showcomplete")){
		void player1 = getplayerproperty(0, "entity"); //IDENTIFY PLAYER 1
		void player2 = getplayerproperty(1, "entity"); //IDENTIFY PLAYER 2
		void player3 = getplayerproperty(2, "entity"); //IDENTIFY PLAYER 3
		void player4 = getplayerproperty(3, "entity"); //IDENTIFY PLAYER 4
		
		if(player1 != NULL()){ //IS PLAYER 1 PLAYING THE GAME??
			setglobalvar("maxRush1", 0); //RESET PLAYER 1 MAX RUSH COUNT SAVED VALUE TO ZERO
		}
		if(player2 != NULL()){ //IS PLAYER 2 PLAYING THE GAME??
			setglobalvar("maxRush2", 0); //RESET PLAYER 2 MAX RUSH COUNT SAVED VALUE TO ZERO
		}
		if(player3 != NULL()){ //IS PLAYER 3 PLAYING THE GAME??
			setglobalvar("maxRush3", 0); //RESET PLAYER 3 MAX RUSH COUNT SAVED VALUE TO ZERO
		}
		if(player4 != NULL()){ //IS PLAYER 4 PLAYING THE GAME??
			setglobalvar("maxRush4", 0); //RESET PLAYER 4 MAX RUSH COUNT SAVED VALUE TO ZERO
		}
	}
}

I hope it helps. You can erase the lines that refers to players 3 or 4 if you are not using them, but make sure that all lines in all scripts are erased, otherwise the game will crash
 
It works perfect at first! A lot of thanks!
I only have some questions more:

- There was already another variable with a "if" on updated.c:

Code:
void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();        
   }
}

void zoom()
{ etc etc

I changed it to:

Code:
void main(){
	resetMaxRush();
	if(getglobalvar("zoomentity"))
	{
      zoom();        
	}
}

void resetMaxRush()
{ etc etc

void zoom()
{ etc etc

This is fine, right?

- These variables are deleted whith this script? If so, how could I prevent it?

Code:
@script
void self = getlocalvar("self");
	if(frame==1)
	{
     		clearglobalvar();
	}
@end_script


- If I enter any stage in a game mode, and then go out and enter another game mode, the maximum combo persists.
Is there a way to delete it when leaving the game, but recover it when loading a saved game? If it can't be done, I don't mind leaving it that way, it's a minor mistake.
EDIT: It is resolved by leaving Openbor and re-entering. I will comment it on readme file and voila!
 
I´m glad it worked Toranks! About the "clearglobalvar" I suggest to add this:
Code:
@script
void self = getlocalvar("self");
	if(frame==1)
	{
		setlocalvar("maxRush1", getglobalvar("maxRush1"));
		setlocalvar("maxRush2", getglobalvar("maxRush2"));
		setlocalvar("maxRush3", getglobalvar("maxRush3"));
		setlocalvar("maxRush4", getglobalvar("maxRush4"));
		clearglobalvar();
		setglobalvar("maxRush1", getlocalvar("maxRush1"));
		setglobalvar("maxRush2", getlocalvar("maxRush2"));
		setglobalvar("maxRush3", getlocalvar("maxRush3"));
		setglobalvar("maxRush4", getlocalvar("maxRush4"));
	}
@end_script
The first 4 lines will save the current rush variable in a local variable. After all 4 are saved, the command "clearglobalvar" will erase all global variables but the local variable are safe. After the global variables are cleared, the rush variables will be loaded from local variables and saved again in a global variable and you will not lose any value.

- If I enter any stage in a game mode, and then go out and enter another game mode, the maximum combo persists.
Is there a way to delete it when leaving the game, but recover it when loading a saved game? If it can't be done, I don't mind leaving it that way, it's a minor mistake.
EDIT: It is resolved by leaving Openbor and re-entering. I will comment it on readme file and voila!
To solve this problem I suggest to add another "if" in your main script in updated.c, like this:
Code:
void main(){
	resetMaxRush();
	if(getglobalvar("zoomentity"))
	{
		zoom();       
	}
	
	//CLEAR ALL GLOBAL VARIABLES AT TITLE SCREEN
	if(openborvariant("in_titlescreen"))
	{
		clearglobalvar();
	}
}
Global variables will be automatically saved by the engine when you start a new level, no need scripts to do it. With this method, if you load a saved game all global variables will be loaded. But if you start a new game, all global variables will be reseted because you can't start a new game before see the title screen before.

If you have any global variable working at the title screen, repeat the same process of the rush script: save global into local > clear > save local into global
Code:
setlocalvar("variable", getglobalvar("variable"));
clearglobalvar();
setglobalvar("variable", getlocalvar("variable"));
 
I do not need any globalvariable on title screen, so everything serves me as it is.

Thanks for everything again, you have helped me a lot. You explain yourself very well, it costs a lot to learn with half of the tutorials that I find, but diving in the forum from time to time you find entries as useful as yours.  ;D :-*
 
Back
Top Bottom