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

Non-platform specific questions.

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

Postby schnellboot » Tue Jul 26, 2011 10:55 am

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.
Attachments
globalcode.ged
no data folder needed
(1.13 KiB) Downloaded 69 times
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

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

Postby foleyjo » Tue Jul 26, 2011 12:07 pm

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: )
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

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

Postby schnellboot » Tue Jul 26, 2011 2:39 pm

what argument do I have to give move() then?
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

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

Postby skydereign » Tue Jul 26, 2011 7:04 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby schnellboot » Tue Jul 26, 2011 8:28 pm

ahh I always read about that but never understood
thank you
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

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

Postby foleyjo » Wed Jul 27, 2011 8:26 am

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?
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

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

Postby skydereign » Wed Jul 27, 2011 8:39 am

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();
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby schnellboot » Wed Jul 27, 2011 9:04 am

I thought comments are completely ignored in the code :)
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

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

Postby skydereign » Wed Jul 27, 2011 9:18 am

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;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest