Page 1 of 1

getclone2

PostPosted: Mon Mar 07, 2005 9:23 pm
by jazz_e_bob
Code: Select all
Actor *getclone2 ( char *actorName, long cloneNumber )
{

  char resultString[256] = "";
  char cloneNumberAsString[10];
  Actor *resultActor;

  strcpy ( resultString, actorName );
  strncat ( resultString, ".", 1 );
  sprintf (cloneNumberAsString, "%i", cloneNumber);
  strncat  ( resultString, cloneNumberAsString, 10 );
 
  resultActor = getclone(resultString);
 
  return resultActor;

}


Paste it into global code editor.

Same usage as "getclone" but you can specify name and clone number separately.

GE Rocks!

Re: getclone2

PostPosted: Fri Jun 06, 2008 11:45 am
by Cleve Blakemore
I think the long passed into the argument above is mismatched for the "%i" integer type. It means the sprintf function will load four bytes of an eight byte number into the substitution argument.

The code below represents a slight improvement in speed and consolidation, it prints both required variables to produce the name string in one pass.

I believe that it is impossible to name an actor with a long enough tag to overflow the 50 character buffer, as well.

I pass the Actor pointer back instead of the reference, so remember use the "->" to get values from it as opposed to the "." for values.

Also remember if you go to get the name of the Actor passed back, "actor->name" is the name without the clone number postfix, you have to use "actor->clonename" to get the full qualified name of the actor involved for passing to functions that take a string argument for the actor's name. (and most do)

Hope this helps someone.

Code: Select all
Actor *g_GetCloneByIndex(const char *cname, int cindex)
{
    char buffer[50];

    sprintf(buffer,"%s.%i",cname,cindex);
 
    return(getclone(buffer));
}

Re: getclone2

PostPosted: Sat Jun 07, 2008 6:43 am
by DST
Very Nice! That works!

And complements JazzEBob's Signature!

I called it 'geti' cause i don't wanna type "g_GetCloneByIndex" every time i wanna use it.

Which is one thing that mystifies me....cleve, you simplified the code, then made a long, hard to type name for it.

Is this the kinda stuff Einstein had problems with? Understanding the universe but being confused by a shoelace?

In fact, here's a question to all u geniuses: why ever have caps or _ in a function name? shift and _ are just more buttons to press! That's why my functions always have names like "shoot" and "shootme" and "gethit".

Keep it ALL simple!

Re: getclone2

PostPosted: Sat Jun 07, 2008 2:50 pm
by Cleve Blakemore
DST wrote:Very Nice! That works!

And complements JazzEBob's Signature!

I called it 'geti' cause i don't wanna type "g_GetCloneByIndex" every time i wanna use it.

Which is one thing that mystifies me....cleve, you simplified the code, then made a long, hard to type name for it.

Is this the kinda stuff Einstein had problems with? Understanding the universe but being confused by a shoelace?

In fact, here's a question to all u geniuses: why ever have caps or _ in a function name? shift and _ are just more buttons to press! That's why my functions always have names like "shoot" and "shootme" and "gethit".

Keep it ALL simple!


It's okay if you've only got one function in your code - but I'm only 25% into the framework for my zombie seige game and I've got 46 routines in the global namespace alone. You want a name that practically explains itself when the variables/functions list pops up in GE because otherwise you are soon confused by what routine does what.

Re: getclone2

PostPosted: Sat Jun 07, 2008 9:13 pm
by jazz_e_bob
Wow. Haven't been here for ages. getClone2 has evolved. Yay!

Busy getting an IT degree, working two jobs and being a dad. Playing lots of bass too.

I've been learning Flash. SO much faster to define game related concepts in GE.

Yes, as simple as possible but no simpler than that...

Love to all!

jazz

Re: getclone2

PostPosted: Sat Jun 07, 2008 9:48 pm
by makslane
:-)

Re: getclone2

PostPosted: Sun Jun 08, 2008 5:16 pm
by Game A Gogo
*bows to Jazz_e_Bob*