Can't access the x or y of a clone in global script?

Non-platform specific questions.

Can't access the x or y of a clone in global script?

Postby bspeers » Fri Aug 10, 2012 4:48 am

EDITED WITH LINK TO .ged AND data file

This I don't get at all.

Here's my code. It works:

Code: Select all
void CheckPoint ()
{
 
viewcheckpointx = screenedge.x;
viewcheckpointy = screenedge.y;
saveVars("autosave.sav", "counters");
saveVars("autosave.sav", "levelswitches");
saveVars("autosave.sav", "flags");
saveVars("autosave.sav", "move");
saveVars("autosave.sav", "input");


 
}


Now if I add this line:

heartx0 = heart.0.x (heartx0 is a variable to store the current location of the heart actor)

I get the message "incompatible types. Cannot convert from struct to long int"

The problem is that a virtually exact same script already works, the "viewcheckpointx = screenedge.x;" line above (which not only doesn't cause an error, but does exactly what I want it to do).

Further, if I try to write the location of heart.0.x, I get the following error: "expected ;" whether there's a semicolon there or not.

Is it because heart.0 is a clone? If so, is there a way to save the x and y of specific clones in Global Script?

I was asked in an earlier question to post my full Ged. Here it is: http://ubuntuone.com/4PkVj9qoAgFls18jbLnxsD
Last edited by bspeers on Fri Aug 10, 2012 1:37 pm, edited 1 time in total.
bspeers
 
Posts: 15
Joined: Thu Jun 21, 2012 2:18 am
Score: 0 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby skydereign » Fri Aug 10, 2012 6:05 am

You can't access clones that way. actor.cloneindex.var is invalid. You need to use an Actor* to get clones. I suggest you read up on the getclone2 function, and how to use them. The Actor* is a pointer to an actor, which you can set with the getclone function.
Code: Select all
Actor* temp_pointer = getclone("enemy.3"); // notice enemy.3 is a clonename (any clonename is valid)
// now temp_pointer can be used to get enemy.3's variables

temp_pointer->x = 0; // sets enemy.3's x to 0


Now using Actor* in global code can cause a few problems. Namely this one. http://game-editor.com/forum/viewtopic.php?f=2&t=12196&p=86470#p86444

Also, you should upload your data directory (not everyone has the same font files). And perhaps you had actual animations in your game, which without it, we wouldn't be able to tell. As AliceXIII mentioned, usually people post a zip file of the ged and data directory.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby AliceXIII » Fri Aug 10, 2012 6:13 am

i was in the middle of typing the exact same response sky, till this laptop backed me out a couple pages odd :roll:
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby bspeers » Fri Aug 10, 2012 1:25 pm

Ah. It's odd though that you can access actor variables in that way as long as there are no clones. I'll read up on getclone2, as I've often found that particular bit of tutorials and help to be confusing.

I'll also update my uploaded game. Like I say, new to the community and the program, I don't know what things are needed for testing, etc.
bspeers
 
Posts: 15
Joined: Thu Jun 21, 2012 2:18 am
Score: 0 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby AliceXIII » Fri Aug 10, 2012 2:37 pm

it's just the way GE reads the member of operator or the '.' using it in this context:

actor.x // it understands that the tag 'actor' is the name of an actual actor

but using it like this:

actor.0.x // GE doesn't understand it because the member of operator gets constant variable's directly associated to your actor like x, y, or transp to where as '.0' isn't a constant variable associated with your actor so there's where the error is created

GE is correct on reading it this way, we as the user just have to understand this is he way the member of operator works :)

this may be beyond you or not but here's exactly why:

the member of operator lets you access variables within a structure a structure is like a repository say
heart is your actor name, heart's actor structure would look something like this in GE's internal code:
Code: Select all
struct heart
{
int x;
int y;
double transp;
etc;
etc;
}

//so then using heart.x, heart.y, or heart.transp we can access the specific variables stored in hearts actor structure but GE doesn't create a '.0' or '.1' variable within the structure because those are references to actor names not actual constant variables that can be used with an actor.


so GE's correct at doing what it does you were just referencing something that doesn't exist, using a pointer to point to said actor then accessing the actor's constant variables is the correct way of doing it as sky said :)
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby bspeers » Sat Aug 11, 2012 4:30 am

Actually I LOVE explanations. That was very informative, thank you.

I only get about 10 minutes a day to script, so I intend to try to get this to work over the next couple days.
bspeers
 
Posts: 15
Joined: Thu Jun 21, 2012 2:18 am
Score: 0 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby AliceXIII » Sat Aug 11, 2012 5:04 am

well i strive to help anyone i can and i always make detailed explanations when needed because it took me some time to learn how GE works exactly which is differnt then just simply using it, and knowing these differences helps alot :)
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Can't access the x or y of a clone in global script?

Postby Fojam » Tue Aug 14, 2012 7:35 pm

this could be fixed if we added a class-like system in GE (which would be SOOOO nice)
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest