Dynamically fetching an actor's co-ordinates

Non-platform specific questions.

Dynamically fetching an actor's co-ordinates

Postby bamby1983 » Sat Mar 23, 2013 12:03 am

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.
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: Dynamically fetching an actor's co-ordinates

Postby skydereign » Sat Mar 23, 2013 12:23 am

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

Re: Dynamically fetching an actor's co-ordinates

Postby bamby1983 » Sat Mar 23, 2013 12:49 am

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. :)
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron