why cant i store this in my actors text??

Non-platform specific questions.

why cant i store this in my actors text??

Postby Fojam » Sat Jul 14, 2012 6:23 pm

i have tried a bunch of different things, and for some reason, no matter what i do, i can get this to store in my actors text?

here is what it looks like. no matter what i do, the actors text doesnt change, but for some reason the dragging still works.

Code: Select all
#define CLICK 0
#define RELEASE 1
#define DRAG 2

void testDragClick(int type)
{
    if(testing==1)
    {
        ChangeTransparency("helper", 0.000000);
        switch(type)
        {
            case CLICK:
            followMouse=1;
            break;
 
            case RELEASE:
            followMouse=0;
            break;
 
            case DRAG:
            if(followMouse==1)
            {
                char thisText[60];
                x=controlBox.x+xmouse;
                y=controlBox.y+ymouse;
                sprintf(thisText, "%s: %i, %i", clonename, controlBox.x+xmouse, controlBox.y+ymouse);
                strcpy(helper.text, thisText);
            }
            break;
        }
    }
}
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

Re: why cant i store this in my actors text??

Postby Hblade » Sat Jul 14, 2012 6:36 pm

Replace sprintf(thisText, "%s: %i, %i", clonename, controlBox.x+xmouse, controlBox.y+ymouse);

with this:
Code: Select all
sprintf(thisText, "%s: %i, %i", clonename, (int)controlBox.x+xmouse, (int)controlBox.y+ymouse);


xmouse and ymouse I think are not int's by default, so adding an (int) next to them should convert then into int values

But you said the text doesn't change.. thats strange... Uh, maybe your missing a .text after thisText
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: why cant i store this in my actors text??

Postby Fojam » Sat Jul 14, 2012 6:47 pm

still no change. it just stays exactly the same. i even tried making an example test program and it still didnt work.
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

Re: why cant i store this in my actors text??

Postby AliceXIII » Sat Jul 14, 2012 7:01 pm

alter it to this and try? since your having to call it from the mouse click even of helperText anyways

Code: Select all
#define CLICK 0
#define RELEASE 1
#define DRAG 2

char testDragClick(int type) //Change it to a char instead of void so the function itself returns an char
{
    if(testing==1)
    {
        ChangeTransparency("helper", 0.000000);
        switch(type)
        {
            case CLICK:
            followMouse=1;
            break;

            case RELEASE:
            followMouse=0;
            break;

            case DRAG:
            if(followMouse==1)
            {
                char thisText[60];
                x=controlBox.x+xmouse;
                y=controlBox.y+ymouse;
                sprintf(thisText, "%s: %i, %i", clonename, controlBox.x+xmouse, controlBox.y+ymouse); //idk about the casting
                return(thisText); //this will return the value on the instance of the function call
                //strcpy(helper.text, thisText); //comment out this
            }
            break;
        }
    }
}


allowing you to just simply in the mouse click event of helperText and say:
Code: Select all
text=thisText;
"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: why cant i store this in my actors text??

Postby skydereign » Sat Jul 14, 2012 7:23 pm

I believe I've mentioned this problem to you before. You can't use actor variables as freely as you'd like in global code. Namely, you can't change them unless the event that calls the function has a reference to the actor. For instance if you have this setup.
Global Code
Code: Select all
void
blue ()
{
    other.r = other.b = 0;
}

first -> Key Down Space -> Script Editor
Code: Select all
blue();

This code will not change the actor named other's color to blue. You need to do this.
Code: Select all
//other
blue();

The only difference is the other reference in the comment tells the game to check to see if the other actor needs its actor variables updated after the script ends. I'm told the reason for this is actor variables have the potential to slow down the game, so gE makes a few optimizations by parsing the scripts. Anyway, a bit unfortunate, but can be worked around.

AliceXIII wrote:allowing you to just simply in the mouse click event of helperText and say:
Code: Select all
text = thisText;

This is the right idea, just make sure to use a strcpy or sprintf, as using equals won't work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: why cant i store this in my actors text??

Postby Hblade » Sat Jul 14, 2012 8:22 pm

Oh yeah!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: why cant i store this in my actors text??

Postby Fojam » Sun Jul 15, 2012 7:56 pm

im kind of confused on what you mean. would using an actor pointer in all of my functions that use actor vars fix it?
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

Re: why cant i store this in my actors text??

Postby skydereign » Sun Jul 15, 2012 11:00 pm

Fojam wrote:im kind of confused on what you mean.

The problem is simple. You can't change another actor's actor variables in global code unless it has been referenced by the script calling the functions. I believe this is bypassed by especial actor types such as creator/parent/collide, but I'm not sure. A reference to an actor is having the actor's name appear in the text of the script.

skydereign wrote:Global Code
Code: Select all
void
blue ()
{
    other.r = other.b = 0;
}

first -> Key Down Space -> Script Editor
Code: Select all
blue();

This code will not change the actor named other's color to blue. You need to do this.
Code: Select all
//other
blue();

The blue function should change actor other's color to blue. But if in the script event that calls the function blue does not have other anywhere in the text, it won't work. So putting // other in the script reminds gE that the other actor actor might have its variables updated. And remember, this is a bug. The comment reference is just a workaround.

Fojam wrote:would using an actor pointer in all of my functions that use actor vars fix it?

No, a similar problem occurs with Actor*. Though it does have a separate fix. Using getclone(clonename_var) I believe will force add the clonename to the updated list. It's been a while though, as I try to avoid this problem entirely.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: why cant i store this in my actors text??

Postby Fojam » Mon Jul 16, 2012 11:50 am

wow ive been doing the thing with clonename so i guess i just got lucky. yeah i was confused because i didnt realize it was a ge bug, because when i saw the comment i didnt understand how that would help it. well im just going to continue using pointers because i really dont want to exploit a bug that may be patched in a new version of ge
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

cron