getclone2

You must understand the Game Editor concepts, before post here.

getclone2

Postby jazz_e_bob » Mon Mar 07, 2005 9:23 pm

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!
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Re: getclone2

Postby Cleve Blakemore » Fri Jun 06, 2008 11:45 am

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));
}
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

Re: getclone2

Postby DST » Sat Jun 07, 2008 6:43 am

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 easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: getclone2

Postby Cleve Blakemore » Sat Jun 07, 2008 2:50 pm

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.
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

Re: getclone2

Postby jazz_e_bob » Sat Jun 07, 2008 9:13 pm

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
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Re: getclone2

Postby makslane » Sat Jun 07, 2008 9:48 pm

:-)
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: getclone2

Postby Game A Gogo » Sun Jun 08, 2008 5:16 pm

*bows to Jazz_e_Bob*
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest