Change a particular clone parameter

Non-platform specific questions.

Re: Change a particular clone parameter

Postby Hblade » Sun May 24, 2015 6:07 pm

try this
Code: Select all
void change_param(char*actor, int param)
{
    Actor*a=getclone(actor);
    a->param_to_change=param;
}


replace "param_to_change" with the variable you want to change.

Then just type this in what ever event changes his params.

Code: Select all
change_param("Enemy.15", 15);


.15 is the 15th clone, the other 15 is the value we're setting.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Change a particular clone parameter

Postby bat78 » Wed Jul 29, 2015 12:29 am

Obtaining pointer to any arbitrary actor is OVERLY slow.
Doing if-checks in 100 actors is still faster (especially if the phenomenon Branch Prediction gets involved)!
So in terms of efficiency, I would go with the Jolteon's straightforward approach.
Assuredly, If I had to choose between either of these.

OP:
You are invoking Undefined Behavior in your code, by committing Stack Overflow. Specifically in that part of your code:
Code: Select all
char array [1];

sprintf(array, "long text" ....

Don't ever do that again, always allocate enough space to contain the formatted string.
And no, LcL, this isn't an array of ONE character, it is an array of TWO characters, which index is either 0 or 1.
Only in order to be a valid STRING, the last character must remain NULL. (If you already know the length of the string you don't really need it to be null-terminated)

Now, concerning the performance (since it appears to be widely questioned in here)
I wouldn't go with neither of your approaches. Sure, obtaining a pointer to any actor on startup time so to not slow down the gameplay is a great idea.

Hblade
I think it is very wasteful to create a function for something that could be achieved on the same basis in one line.
Not only wasteful but a bad practice as functions are meant for processing, not to spare some lines. Macros are meant to spare some lines.
If you use gE1.4.1b you can use the getclone2 function, just like that:
Code: Select all
Actor* c = getclone2(myactor.name, 27); c->yvelocity = 2;

or
Code: Select all
getclone2(myactor.name, 27) -> yvelocity = 2;

where myactor is the actor you want to get a pointer to and where 27 is its clone index.
If you don't use the latest Game-Editor, then create the function yourself:
Code: Select all
#define ACTOR_MAX_NAME_LENGTH (26)
#define ACTOR_MAX_CLONES_DIGIT (3)

Actor* getclone2 (const char cloneName[ACTOR_MAX_NAME_LENGTH + 1], const int cloneIndex)
{
    char newName [ACTOR_MAX_NAME_LENGTH + 1 + ACTOR_MAX_CLONES_DIGIT + 1]; // maximum 999 clones for a reason

    // If padding 0s were not a concern..
    //sprintf(newName, "%.*s.%.*i", ACTOR_MAX_NAME_LENGTH, cloneName, ACTOR_MAX_CLONES_DIGIT, cloneIndex);
    sprintf(newName, "%.*s.%i", ACTOR_MAX_NAME_LENGTH, cloneName, cloneIndex);

    return getclone(newName);
}


If you declare
Code: Select all
Actor* c;

in global code, you can initialize it from any actor's code:
Code: Select all
c = getactor(myactor.name, 27);

And use it everywhere.

In functions that require the target actor to be presented as a string, you can do:
Code: Select all
c->clonename


Example:
Code: Select all
MoveTo(c->clonename, 0.000000, 0.000000, 2.000000, "Game Center", "");

or
Code: Select all
MoveTo(getclone2(actor.name, 2)->clonename, 0.000000, 0.000000, 2.000000, "Game Center", "");

Depending on your intentions with the actor pointer.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Change a particular clone parameter

Postby Zivouhr » Fri Nov 06, 2015 1:07 am

lcl wrote:
Code: Select all
getclone("ThatActor.26")->yvelocity = 3;

It's better to learn to use getclone than to use if checks for cloneindex. Think if you have hundreds of clones and you tell them all to check if their cloneindex is 26 just in order to change that specific clone's yvelocity.. Not efficient.


Will the
enemy/create actor/script editor:
Code: Select all
if(cloneindex==1001) r=10;

code repeated 1001 times slow down the game's performance noticeably?

I believe you if you're saying using getClone instead of if for the same result, to tell the clone what to do if I have 1001 clones to give commands to. Thanks. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron