Load code from a file?

Non-platform specific questions.

Load code from a file?

Postby CrimsonTheDarkBat » Sun Oct 23, 2011 12:39 pm

Hey all, quick question:

Is there a way to make an actor export some text (code) to a file?
And then in another .dat file (a menu, for example) can the exported code be read and executed?

All I want is a way so upon completion of a level, the players score are exported along with a LoadGame command for the next level. Then at the start of the loaded level, the players previous score would be loaded?

Im really hurting for this feature - please help me in whatever way you can. :)
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby lcl » Sun Oct 23, 2011 1:13 pm

So, you want to save a variable and then load it.
There's about 1000 topics about that and as many and even more answers, please use the forum search for these in future.. :wink: most questions people have are already answered, it's just the matter of searching the answer, which takes just few minutes.. I think you know what I mean? :D

Anyway, here's a link to one tutorial, the topic just under this in support forum:
viewtopic.php?f=2&t=11190#p78059
Just use it for points instead of lives.. :D

- lcl -
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Load code from a file?

Postby CrimsonTheDarkBat » Sun Oct 23, 2011 1:48 pm

Thanks mate, that seems good for the score :D sorry, I'll search in future xD

Anyway, thats one issue resolved - but how can I make the game save progress after every level and then allow the player to load the game from the main menu? Ive read many topics on this but none seem to make sense to me. :/ anyone care to walk me through it? ^^

if it helps, the naming schemes for my games files are like this:

(levels)
Stage1.dat
Stage2.dat
Etc...

(cutscenes)
Cut1.dat
Cut2.dat
Etc...

(bosses)
Boss1.dat
Boss2.dat
Etc...
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby lcl » Sun Oct 23, 2011 1:58 pm

Well, it's just the same as saving the score, you give variable a save group and then use saveVars() and loadVars() for saving and loading the values.

Here's the parameters that saveVars() and loadVars() need

saveVars(filename, savegroup);
loadVars(filename, savegroup);

So, if your variables had save group named SavedVariables and you wanted to save to file named Saves.dat, you'd write:
Code: Select all
saveVars("Saves.dat", "SavedVariables);

And for loading:
Code: Select all
loadVars("Saves.dat", "SavedVariables);


:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Load code from a file?

Postby CrimsonTheDarkBat » Sun Oct 23, 2011 6:40 pm

Dude sorry but I just cannot get this thing working - i'm a complete noob at using the Script Editor - all this talk about variables has me mindfooked! ^^;

Can some one just give me a detailed explaination on how to do this? Baby steps is what I need here.
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby Jagmaster » Sun Oct 23, 2011 7:40 pm

A variable is just holds a value. To save that value into a file, you use the saveVars function.
Once you get the hang of the script editor, you will have much more flexibility and organization. :D

Here is a step-by-step tutorial for making a checkpoint. Complete with pictures.
Code: Select all
 http://game-editor.com/forum/viewtopic.php?f=4&t=8744
If you need any more tutorials, there are plenty more on the tutorials page on the main site.
Code: Select all
http://game-editor.com/Tutorials
Code: Select all
http://game-editor.com/Help
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Load code from a file?

Postby CrimsonTheDarkBat » Sun Oct 23, 2011 8:52 pm

Thanks Jagmaster, finally got the score to save/load properly :)

However, im still stuck for saving level progress. How can i set up a way of having the game save the next .dat filename in the save file, then have the player be able to load that level from the menu? Please help me, this is the last critical issue in my game that needs fixing.
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby Jagmaster » Sun Oct 23, 2011 9:47 pm

What I would do for sake of simplicity, would be to make a new var called levels_complete or something like that and have it saved in a separate group, like maybe "completion"
On completion of level.
(collision on flag)
Code: Select all
loadVars(Filename, group);
levels_complete++;
saveVars(Filename, group);


then on mouse down of your button:
Code: Select all
loadVars(Filename, group);
switch(levels_complete)                                   // More info on switch --> http://game-editor.com/Switch
{

case 0:                             // <---Use a colon here.
LoadGame(lvl1);
break;                             // <--- Do not forget break!

case 1:
LoadGame(lvl2);
break;
                                     //and so on...
}


Of course, you would need to replace all the other vars with your own. This should do the trick. :)
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Load code from a file?

Postby CrimsonTheDarkBat » Tue Oct 25, 2011 1:16 pm

I can't get this code to work :(

When I click the load game button in the main menu, it just re-loads the menu again, as though it's trying to load a non-existant file or something. :/

Any help?
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby Jagmaster » Tue Oct 25, 2011 1:27 pm

Did you include the file extension with the file name in the loadgame function?
One thing to note, loadgame doesn't always work in the editor. In fact, in the exported file, you don't even need to include the extension at all. In the editor, the only files I've successfully loaded with that function were .ged files.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Load code from a file?

Postby CrimsonTheDarkBat » Tue Oct 25, 2011 1:33 pm

Yup, I've tried that too - still getting the same result. :(
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Load code from a file?

Postby Jagmaster » Tue Oct 25, 2011 1:50 pm

Take a look at this ->test
load test.ged, then click the text. You will cycle through levels and then go back to the menu. If you click the text now, you will be at lvl 2.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest