text documents

Non-platform specific questions.

text documents

Postby BogdansB » Sun Apr 29, 2012 12:03 pm

hi everybody,
I want to make a game with 2 files. one file is where a player walks an a platform and when he wants to fight another file opens , where you can fight.

in the 1st file there would be variables for strenght and dextery and stuff. i want them to save in a textdokument and when the 2nd file opens, the data of for example strenght goes to the 2nd file and there it will save in a variable...

how can i do it in a script ?

is it like:

FILE*file=fopen("file.txt",r+);
data=fgets(file,10);
fclose(file);

?

and now the data has the value which was in the document?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: text documents

Postby SuperSonic » Sun Apr 29, 2012 1:18 pm

BogdansB wrote:and now the data has the value which was in the document?

If "data" is an array, then yes :)
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: text documents

Postby BogdansB » Sun Apr 29, 2012 2:33 pm

?? i thought you need to make a variable , so data is a variable...

how to make an array and what does it stands for?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: text documents

Postby SuperSonic » Sun Apr 29, 2012 9:33 pm

A variable is simply a chunck of memory used to store information :)

To create an variable in Global code, you have to follow this template:
Code: Select all
datatype name;

Datatype is the type of data you want to store (number, decimal, etc). You must replace it with int (number), char (text character), or float (decimal). Then you have to replace "name" with whatever you want to call the variable. Here's an example:
Code: Select all
int MyVariable;//Creates a variable called "MyVariable" that stores a number

Now an array is simply a line of variables that all share the same name. Here's how you create an array:
Code: Select all
datatype name[number];
As you can see, this is just like declaring a variable except you have those brackets with a number inside. The number stands for how many variables you want the array to store. For example, if you replace it with 5, the array will store five variables starting at 0 and ending at 4. Here's an example of declaring an array:
Code: Select all
int MyArray[5];//Creates five variables that store numbers

Now, to access a variable from an array, you need to give the name of the array followed by the number of the variable you want to call surrounded by brackets. That might sound confusing but it's really easy. Here's what it looks like:
Code: Select all
int MyArray[5];//Creates five variables that store numbers
MyArray[0] = 10;//Sets the first variable equal to ten
MyArray[1] = 8;//Sets the second variable equal to eight
MyArray[2] = 6;//Sets the third variable equal to six
MyArray[3] = 4;//Sets the fourth variable equal to four
MyArray[4] = 2;//Sets the fifth variable equal to two

Now, it's important to remember, that an array variabel and a normal variable are actually the same thing, and you can use them with eachother. Here's an example:
Code: Select all
int MyVariable;//Creates a variable called "MyVariable" that stores a number
int BobsVariable;//Creates a variable called "BobsVariable" that stores a number
int JanesArray[2];//Creates an array called "JanesArray" that stores two numbers
JanesArray[0] = 5;//Sets the first variable equal to five
JanesArray[1] = 8;//Sets the second variable equal to eight
MyVariable = JanesArray[0];//Sets "MyVariable" equal to the first variable in "JanesArray"
BobsVariable = JanesArray[0];//Sets "BobsVariable" equal to the second variable in "JanesArray"

Now, in your case, you want an array called "data" that stores ten text characters. You can create that in Global Code like this:
Code: Select all
char data[10];

If you do that, then your code should work just fine :wink:

If you have questions, or if I made any grammatical errors, etc, then post here or send me a PM :P

-Sonic-
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: text documents

Postby lcl » Tue May 01, 2012 8:22 am

Hey BogdansB have you heard of SaveVars() and LoadVars()?
They are built in GE functions for doing easily just what you are trying to do now.

You create the variables that you want to save and you give them a save group.
Then you use SaveVars() and give it the name of the file to write to and the name of the group you want to save.
For loading the variables you do the same with LoadVars().

That's what GE's documentation says about them:
(The documentation can be found at: http://game-editor.com/docs/script_reference.htm)
GE documentation - script reference wrote:Save functions

Use saveVars and loadVars to save and load any variables in a game, like highscores, current lives, etc. To use these functions, you must use the "Save group" field in the "Add New Variable" panel (Variable button in the Script Editor).

saveVars: Save all variables in the group to the specified file.
The file will be saved in the game directory.
void saveVars(char *file, char *group)

Use saveVars to save any variables in a game; highscores, current lives, etc.
You must use the "Save group" field in the "Add New Variable"panel (Variable button in the Script Editor).

Script Editor Syntax:
saveVars("game.sav", "High Score");

loadVars: Load all the variables in the group from a specified file.
void loadVars(char *file, char *group)


Script Editor Syntax:
loadVars("game.sav", "High Score");

Example:
1. Create a "score" variable and put it in the "High Score" group.
2. Create two more variables: "lives" and "energy". Put these variables in the "Actor State" group.

When the player dies, use saveVars("game.sav", "High Score"); to save the current player's high score without saving the player's state.
When the user exits the game, use saveVars("game.sav", "Actor State"); to save the current player's state (lives and energy).
Note: different variable groups can be saved in the same file (game.sav).
Finally, use loadVars("game.sav", "High Score"); and loadVars("game.sav", "Actor State"); in the proper script editor area of the game!
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: text documents

Postby BogdansB » Tue May 01, 2012 11:28 am

thank you very much :D
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron