Page 1 of 1

setting string vars in Create Actor evet not working

PostPosted: Wed Jan 04, 2006 7:48 am
by fauldran
I have several string variables defined as actor variables. I am trying to use the Create Actor event to give these vars default values for an actor. The vars are then used in the Draw Actor event.

The problem is that the variables are empty when the Draw Actor code executes.

Using the same method with integers works fine though. Is this a bug with strings or am I missing something?

PostPosted: Wed Jan 04, 2006 12:16 pm
by makslane
Can you post the code used to initialize the strings?

The Details...

PostPosted: Wed Jan 04, 2006 7:42 pm
by fauldran
I have several string variables (anim_move_N, ..E, ...W, etc...) that were created through the Variables dialogue as actor variables.

The intent is to use these to store the names of animations to be used when the actor is moving in a given direction.

on our character AI_ghost:
--Create Actor--
//the first two are integers and are working fine
moving = 0;
dir = 0;

//then we have the strings that are not working
anim_move_N = "ghost_move_N";
anim_move_NE = "ghost_move_NE";
anim_move_E = "ghost_move_E";
anim_move_SE = "ghost_move_SE";
anim_move_S = "ghost_move_S";
anim_move_SW = "ghost_move_SW";
anim_move_W = "ghost_move_W";
anim_move_NW = "ghost_move_NW";

--Draw Actor--
//I have a switch on dir that determines an animation to use. In each case is the following:

if(animindex != getAnimIndex(anim_move_N))
{
ChangeAnimation("Event Actor", anim_move_N, FORWARD);
}

The problem is that when Draw Actor executes anim_move_N (or whichever relative animation var) is empty.

---------------Work Around------------------
I am able to get around this by placing the strings in the Draw Actor script. However as I understand it this will slow execution because it would be reassigning these values every frame right?

--Draw Actor--
anim_move_N = "ghost_move_N";
anim_move_NE = "ghost_move_NE";
anim_move_E = "ghost_move_E";
anim_move_SE = "ghost_move_SE";
anim_move_S = "ghost_move_S";
anim_move_SW = "ghost_move_SW";
anim_move_W = "ghost_move_W";
anim_move_NW = "ghost_move_NW";

//with the switch following.


I would be happy to send you the game files if you would like. Thanks for the help.

PostPosted: Thu Jan 05, 2006 12:23 pm
by makslane
With strings you need to use the strcpy function:

strcpy(anim_move_N, "ghost_move_N");

PostPosted: Thu Jan 05, 2006 5:52 pm
by fauldran
Ahhh, I have to get used to using the strcpy. Did not even think to try that in this case. Works great now. Thanks!

PostPosted: Fri Jan 06, 2006 6:13 pm
by plinydogg
I was accidentally using textNumber instead of strcpy and so am just learning about strcpy. My question is: when I use strcpy I get a warning saying "suspicious pointer conversion." Do I need to be worried about this?

Thanks.

PostPosted: Fri Jan 06, 2006 6:33 pm
by plinydogg
I guess I do need to worry about it since I get access violations whenever that code executes.

To make a long story short, here's what I'm trying to do:

(1) When game starts, load global high score variables (name, level, and score) using LoadVars (this part works fine);
(2) If the player has a score greater than the lowest high score, the view moves to a screen that allows the person to input his/her name (this part also works fine);
(3) When the person clicks on the word "Enter," scores are reassigned (e.g., if player's score > 5th high score but < than 4th high score, player's score is assigned to the global highScoreFive variable, etc.);
(4) Finally, the altered high scores should be assigned to the actors that display them. I initially tried using something like

highScore01Name.textNumber = Score01Name;

That didn't work.

Then I tried

strcpy(highScore01Name.text, Score01Name);

which created the access violations.

Does anyone have any advice?

Thanks again!

PostPosted: Fri Jan 06, 2006 7:25 pm
by makslane
Score01Name must be a string, not a integer

PostPosted: Fri Jan 06, 2006 8:01 pm
by plinydogg
I'm an idiot :( Thanks for your patience!