Clones and strings ect. trouble

Game Editor comments and discussion.

Clones and strings ect. trouble

Postby jimmynewguy » Sat Dec 10, 2011 2:56 pm

I've always seemed to have a problem with strings and clones and Actors when it comes to clones and all that.
On draw actor of an enemy I have this to get all the actors it's colliding with and to see if they're in the range, and then get the closest one.
Code: Select all
int i, n, mindist = 1000;
Actor * cols = getAllActorsInCollision(range, &n);
Actor * closest = NULL;
for(i = 0; i < n; i ++)
{
 
if(cols[i].team == 1)
{
int d = distance(x, y, cols[i].x, cols[i].y);
if(d < mindist)
{
closest = (cols + i);
mindist = d;
}
if(closest)
{
target[cloneindex] = closest;
attack = 1;
}
else
{
target[cloneindex] = NULL;
attack = 0;
}
}
}
}

Then, on animation finish I have this:
Code: Select all
int i;
if(attack)
{
attack = 0;
if(target[cloneindex] != NULL)
{
target[cloneindex]->hp -= 1;
}

But the target never loses hp. I made a debug string actor and it has
Code: Select all
sprintf(text, "%s: %i", target[0]->clonename, orc.attack

And it correctly displays the clone name of the orcs target and it says it's attack is 1. Obviously I left out the script that does animations, but it all works fine. The orc faces the target, he will move toward the target, he will attack the target, the target just will not lose health. The animation scripts change no variables either.
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Clones and strings ect. trouble

Postby jimmynewguy » Sat Dec 10, 2011 4:28 pm

Okay, it must really have something to do with stuff I just don't understand.
I added this to the top of the animation finish script and subtracted health from the targeted actor instead and it works?
Code: Select all
Actor * targeted = getclone2(target[cloneindex]->name, target[cloneindex]->cloneindex);
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Clones and strings ect. trouble

Postby skydereign » Sat Dec 10, 2011 8:42 pm

It's a problem with using Actor*s. Logically you shouldn't need to do that, but due to gE's actor setup, it is necessary.
http://game-editor.com/forum/viewtopic.php?f=2&t=10615&p=75404&#p75404
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Clones and strings ect. trouble

Postby jimmynewguy » Sat Dec 10, 2011 8:46 pm

Weird, guess I should've looked around for a post like that. Thanks sky. But it turns out having several actors check variables for several actors in a loop is really slow, so I'm going to remake all of what I have done so far. When there's something going on with more than 30 units on the field now it lags to 15 fps. I'm just going to tie all the units into a units[][] 2d array that DST always told me to do now that I understand what he was talking about all this time!
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest