Page 1 of 1

Dynamically fetching an actor's co-ordinates

PostPosted: Sat Mar 23, 2013 12:03 am
by bamby1983
I've been trying to make some reusable functions to ease game development using GE but I keep running into the following issue.

Let's say I have a function that reads the X co-ordinates of one actor and writes this value to the X co-ordinates of another actor. Both actor names should be accessed as parameters in a function, while the code to read and modify the X co-ordinates lies within the body of that function.

For example:

Code: Select all
void teleport (actor_to_be_teleported, teleport_location_actor) { // Function to teleport an object
    // Code to assign the x and y co-ordinates of teleport_location_actor to actor_to_be_teleported
                       }


I would then want to call this function by specifying the actor names as parameters.

Code: Select all
teleport("Player_1","Player_2");


How would I use actor_to_be_teleported and teleport_location_actor, which contain the names of these actors, to assign the X and Y co-ordinates of one to the other? I can't directly use actor_to_be_teleported.x as that would result in an illegal structure error.

Re: Dynamically fetching an actor's co-ordinates

PostPosted: Sat Mar 23, 2013 12:23 am
by skydereign
You need to be using getclone, to get the Actor* of the actor. Using that you can access the x, y, or any actor variable by using the -> operator. I suggest searching up getclone2 on the forums, as well as looking at getclone in the script reference.

Re: Dynamically fetching an actor's co-ordinates

PostPosted: Sat Mar 23, 2013 12:49 am
by bamby1983
Thanks for the quick response, Sky. I forgot that getclone allows us to specify the actor name as a string. This solves my problem!

I'll share any reusable functions I make with the community. :)