Help with saving an actor's state please.

Non-platform specific questions.

Help with saving an actor's state please.

Postby Just4Fun » Wed Apr 19, 2006 4:46 pm

Hi,

I'm struggling with saving an actor's state. Here is what I would like to do.

-On exiting the game
--save the current actor's animation.

---For example:

I have an actor who has two animations.
----On a mouse down event, the animation changes from anim1 to anim2.
On exiting the game, I want to save each actors anim.
If it is anim1 then save it or if it is anim2 then save it.

----When the game restarts, I want the same game state as I had previously with each actor's animation displaying what it was when the game was exited.

I've searche the forum, reread the docs and I still can't seem to make the intellectual jump from the excellent examples and information to what I am trying to do. Any help is appreciated. TIA
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby DilloDude » Wed Apr 19, 2006 10:05 pm

Have a command for save. Enter the following in global code:
Code: Select all
void ASBI(int AI, int animation_direction)
{
    if (animindex != AI)
    {
        ChangeAnimation("Event Actor",  getAnimName(AI) , animation_direction);
    }
}

Create an actor variable that is saved in a save group. On your save command (eg keydown or mose button)
Code: Select all
var = animindex;
SaveVars(...

On a load game command:
Code: Select all
LoadVars(...
ASBI(var, FORWARD);
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Just4Fun » Thu Apr 20, 2006 3:02 pm

Thanks DilloDude:

I wonder if there isn't some more simplified way of solving this issue. Maybe by using the animindex in the variable (actor_anim)and calling the animindex on loadVars("game.sav", "actor image");

I've tried doing the above, but can't seem to get it to do work. Do you know what the proper code would be for this or even if it would work? I like your solution, but I'm trying to use GE functions as much as possible to simplify the work... I've never claimed to be an expert with C programming though I am learning. My goal is to use GE as much as possible as an authoring system and use scripting as little as possible. When I do script, I like to try to get more familiar with GE's built in functions in order to see if they will simplify what I am trying to do.

Thanks again for your expert help. If anyone else has solutions that they have used, please do jump in and join this conversation. I really like seeing various solutions to a problem. It helps the learning process. TIA
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby makslane » Thu Apr 20, 2006 3:57 pm

You need create a global var, before use saveVars, and make your value wual to the animindex
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Just4Fun » Thu Apr 20, 2006 6:39 pm

Thank You Makslane.

Here is what I have(the basic idea came from an earlier post by jazz-- Where is that guy anyway?):

Event Create Actor --> Script Editor Code:
loadVars ("game.sav", "actor anim"); //load oldAnimIndex variables
animindex=oldAnimIndex;

if ( animindex == getAnimIndex("Image1") )
ChangeAnimation("Event Actor", "Image1", FORWARD);
else
ChangeAnimation("Event Actor", "Image2", FORWARD);

Event Mouse Down --> Script Editor Code:
//get the proper animation based on the current animindex

if ( animindex == getAnimIndex("Image1") )
ChangeAnimation("Event Actor", "Image2", FORWARD);
else
ChangeAnimation("Event Actor", "Image1", FORWARD);
oldAnimIndex = animindex; //capture the current animindex

Event Mouse Up --> Script Editor Code:
animindex=oldAnimIndex; //assign the current animindex to oldAnimIndex
saveVars ("game.sav", "actor anim"); //save oldAnimIndex variables in actor anim group

*Does this code look OK? It seems to work, but maybe there is something that could be changed or removed. Thanks everyone. :D
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby DilloDude » Thu Apr 20, 2006 11:26 pm

Looks ok. The only thing is that animindex is a read-only variable so I don't know if you can change it to oldAnimIndex, so try if(oldAnimIndex == getAnimIndex("Image1"))
ChangeAnimation...
oldAnimIndex = animindex
if you have any problems.

Another tip, if you have lots of variables to save (eg. x, y, animindex, health etc.) you can make an array.
Then you can say
Code: Select all
Save[0] = x;
Save[1] = y;
Save[2] = animindex;
Save[3] = health;
...

and save the whole thing as one variable.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby WauloK » Fri Apr 21, 2006 1:28 am

DilloDude wrote:Then you can say
Code: Select all
Save[0] = x;
Save[1] = y;
Save[2] = animindex;
Save[3] = health;
...

and save the whole thing as one variable.


And use #define's

#define PLAYERX 0
#define PLAYERY 1
#define ANIMINDEX 2
#define HEALTH 3

Code: Select all
Save[PLAYERX] = x;
Save[PLAYERY] = y;
Save[ANIMINDEX] = animindex;
Save[HEALTH] = health;
...


Easier to remember when you read the code another day :)
Available for Beta-testing.. PM me!
Black 16Gb iPhone 3GS
Windows 7: 2Gb RAM. Dell 9150.
WauloK
 
Posts: 42
Joined: Wed Apr 19, 2006 3:19 am
Location: Sydney, Aussieland
Score: 0 Give a positive score

Postby Just4Fun » Fri Apr 21, 2006 2:16 pm

Wow! You guys have such great ideas. Thank you. I was wondering how to save more than one variable. :D
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby DilloDude » Sat Apr 22, 2006 12:53 am

What's the difference between saying #define PLAYERX 0, and const int PLAYERX = 0?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby WauloK » Sat Apr 22, 2006 5:11 am

DilloDude wrote:What's the difference between saying #define PLAYERX 0, and const int PLAYERX = 0?


#define won't use up memory during the game by declaring an integer of PLAYERX and setting it to 0
#define is only used for your own benefit and is converted straight to 0 during compile.
Available for Beta-testing.. PM me!
Black 16Gb iPhone 3GS
Windows 7: 2Gb RAM. Dell 9150.
WauloK
 
Posts: 42
Joined: Wed Apr 19, 2006 3:19 am
Location: Sydney, Aussieland
Score: 0 Give a positive score

Postby Fuzzy » Sat Apr 22, 2006 5:38 pm

DilloDude wrote:What's the difference between saying #define PLAYERX 0, and const int PLAYERX = 0?


Define is a special way to expand text from the define name into the data that follows it.

for example, if you have a long formula, you can just place it in a define statement, rather than calling a function. Functions have to do all sorts of stack pushes, variable saving, and pointer references, so they create overhead. sometimes you need them though.

Basically, everything that follows the #define name will be inserted into the code at the point that you use the keyword. this is why we dont use = or ; with define. they would get added too.

I am doing a lesson on creative uses for define right now.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest