1. Access actor's clone name through name
You can get the clone name of arbitrary actor through name just as if you were using clonename instead.
All simply by virtue of some inferior pointer arithmetic:
- Code: Select all
sprintf(text, "My text actor's clone name is: %s", name + 33);
Explanation:
There is nothing much to explain. This is a matter of structure alignment / packing and since name is an offset address of statically allocated array of chars to represent the actor's name, 33 bytes forwards will aways reach the offset address of the clone name.
Could be useful:
If any of us have some time, we can create macros to represent pointer arithmetic to any of the Actor members.
With that, we can get rid of the nasty gE bug with being unable to access actor's property members unless with getclone.
(I already have a good idea of how to imply it)
2. Function to save/load actor state to/from file.
No more confusing and needless to say slow gE variable declaration using the gE built-in save system. Now you can automatically save or load unique data for all actors. With this, you can recover actor state from previous game just with one function call. Put this in global code:
- Code: Select all
#define ACTOR_SAVE (0x1)
#define ACTOR_LOAD (0x2)
#define OFFSET_OF_CLONENAME name + 0x21
#define STRINGIFY(s) #s
void ActorState (const char cloneName [], const int action)
{
Actor* aPtr;
FILE* fPtr;
if(action != ACTOR_SAVE && action != ACTOR_LOAD) return();
if(action == ACTOR_SAVE)
{
aPtr = getclone( cloneName );
fPtr = fopen ( aPtr->OFFSET_OF_CLONENAME , STRINGIFY(wb) );
if(fPtr) fwrite(aPtr, 1, sizeof(Actor), fPtr);
fclose(fPtr);
return();
}
fPtr = fopen ( cloneName, STRINGIFY(rb) );
aPtr = getclone( cloneName );
if(fPtr) fread(aPtr, 1, sizeof(Actor), fPtr);
fclose(fPtr);
}
Usage:
To save actor, just do this:
- Code: Select all
ActorState(clonename, ACTOR_SAVE); // or actor.clonename where actor is the name of the actor you wish to save
To load the actor:
- Code: Select all
ActorState(clonename, ACTOR_LOAD); // or actor.clonename where actor is the name of the actor you wish to load