Page 1 of 1

Getting the last clone?

PostPosted: Fri Aug 19, 2011 9:10 am
by ikarus
Making a health bar where an actor is made for each health gained and the last clone is destroyed for each hp lost. Problem is DestroyActor needs a string. Now I'm trying to get my head around the deadly low level C code I've never had to deal with before. After some googleing this is what I got.

Code: Select all
int index = ActorCount("HP");
index -= 1;
char buffer[255];
char name[255] = "HP."
buffer = (char)index;
name = strcat(name, buffer);
DestroyActor(name);

It gives an error of something like "cannot convert from 'char' to 'ARY[255]char'
Can someone please tell me what I'm doing wrong? Or even better please tell me there's an easier way to do this???

Re: Getting the last clone?

PostPosted: Fri Aug 19, 2011 12:27 pm
by skydereign
Well, not sure why you need to create actors, as using an animation for that is much easier (like an animated health bar), but to destroy the last clone, assuming you only ever destroy the last clone (so essentially only this code will destroy the HP actor), you have to do something like this.
Code: Select all
char buffer[50];
sprintf(buffer, "HP.%d", ActorCount("HP")-1);
DestroyActor(buffer);


You keep talking about how low level c is, and while yes it is, gE c isn't all that low level. Pretty much everything is provided for you, with the exception of strings, which for almost all cases you can use sprintf.

Re: Getting the last clone?

PostPosted: Fri Aug 19, 2011 4:06 pm
by ikarus
Thanks, been searching the script reference for "string" or "char", realized I should of searched for "text". And O.o... I was just kidding about the low level thing lol, if there weren't all of ge's helper functions I'd be in over my head lol. I'm primarily a high-level language programmer so I relish the thought, just saying at least C's syntax is copied so much so I at least already lmao

Oh and this is a game where you really have to watch your health closely, so I need a way to make it clear, think of it as kinda similar to the health system from zelda.

Re: Getting the last clone?

PostPosted: Fri Aug 19, 2011 7:44 pm
by skydereign
Yeah, I kind of figured you were joking, the statement though begged a response. Anyway, most games made with gE don't require any of the really low level stuff in c. But, since the health system is like zelda's then that method should work fine as the highest cloneindex will always match. That wouldn't be the case if you destroy one that is not the most recently created clone.

Re: Getting the last clone?

PostPosted: Wed Aug 24, 2011 7:13 am
by ikarus
skydereign wrote:...Anyway, most games made with gE don't require any of the really low level stuff in c.


Yeah.... But then again the JustForTheHellOfItYouGottaTryIt fairy begs otherwise