Page 1 of 1

Set X and Y of another actor using a function (void)

PostPosted: Tue Jul 26, 2011 10:55 am
by schnellboot
Hey guys,
when I make this function in global code
Code: Select all
void move()
{
    player.x+=10;
}


I can only execute move(); in player actor itself.
When I execute it in another actor nothing happens.
Also when I execute it in another actor and then try to execute in player actor nothing happens.

Re: Set X and Y of another actor using a function (void)

PostPosted: Tue Jul 26, 2011 12:07 pm
by foleyjo
Hi

I'm currently struggling with functions at the moment.

I think what you need to do in this situation is make the first line

Code: Select all
void move(char * ActorToMove)


and then when you call the function you pass the clone name of the actor that you wish to move.

Then do
Code: Select all
Actor * MoveThis = GetClone(ActorToMove);
MoveThis->x+=10;


Not sure if this is how your supposed to work with functions but I'm having more success when I do things this way.
(also note that I don't know if this will work because I haven't tested it. It probably won't. I hate functions at the moment :evil: )

Re: Set X and Y of another actor using a function (void)

PostPosted: Tue Jul 26, 2011 2:39 pm
by schnellboot
what argument do I have to give move() then?

Re: Set X and Y of another actor using a function (void)

PostPosted: Tue Jul 26, 2011 7:04 pm
by skydereign
That is a problem with global code. You can make it work, but you have to do this.
Code: Select all
//player
move();


Any actors not specified (as in you never write their actor name in the script) cannot be updated. That means the change to the player's x will be ignored. One way of getting around this problem is to have your functions take an actor name (like in foleyjo's example). That way whenever you call it, you have automatically written its name in the script, and it will know to update the variables. Pretty lame workaround, but that is what happens when you try to use actor.actorVar in global script.

Re: Set X and Y of another actor using a function (void)

PostPosted: Tue Jul 26, 2011 8:28 pm
by schnellboot
ahh I always read about that but never understood
thank you

Re: Set X and Y of another actor using a function (void)

PostPosted: Wed Jul 27, 2011 8:26 am
by foleyjo
schnellboot wrote:what argument do I have to give move() then?


In the example I gave for the player actor you would use

move(player.clonename);

for any other actor you would use

move(*actor*.clonename);


Skydereign could you just clarify - If you are wanting to pass the event actor into the function you need to add the event actors name somewhere in the code as a comment and then you can just use move();. Or am I way off?

Re: Set X and Y of another actor using a function (void)

PostPosted: Wed Jul 27, 2011 8:39 am
by skydereign
Not really. If you want to edit the event actor's variables in a function, all you need to do is use the variables.
Code: Select all
void
move ()
{
    x+=10;
}


That code will work without problem. The following code will also work if only the player actor calls it (and there is only one player actor).
Code: Select all
void
move ()
{
    player.x+=10;
}

But because it can only be called by the player, that function is really useless.

You would however use a function that moves actors using similar methods for a function like this (moves all the menu type graphics off screen).
Code: Select all
void
reset_menu ()
{
    menu.x=-3000;
    pause.x=-3000;
    hiscore.x=-3000;
    credits.x=-3000;
}

But to call this you need to have those actor names in the event code (usually in a comment).
Code: Select all
//menu pause hiscore credits
reset_menu();

Re: Set X and Y of another actor using a function (void)

PostPosted: Wed Jul 27, 2011 9:04 am
by schnellboot
I thought comments are completely ignored in the code :)

Re: Set X and Y of another actor using a function (void)

PostPosted: Wed Jul 27, 2011 9:18 am
by skydereign
Yeah... they aren't supposed to be read. What gE does, from what I've seen in the source, is parse the entire script for certain keywords, such as actor names. Any actors found this way can be updated. This was makslane's fix at the time, and hopefully will be fixed soon. Parsing the function it calls shouldn't be that hard to do, and would fix the problem... but until then we have to use comments, or some other way of writing the actor's name (like the following).
Code: Select all
player;