Page 1 of 1

why cant i store this in my actors text??

PostPosted: Sat Jul 14, 2012 6:23 pm
by Fojam
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;
        }
    }
}

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

PostPosted: Sat Jul 14, 2012 6:36 pm
by Hblade
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

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

PostPosted: Sat Jul 14, 2012 6:47 pm
by Fojam
still no change. it just stays exactly the same. i even tried making an example test program and it still didnt work.

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

PostPosted: Sat Jul 14, 2012 7:01 pm
by AliceXIII
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;

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

PostPosted: Sat Jul 14, 2012 7:23 pm
by skydereign
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.

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

PostPosted: Sat Jul 14, 2012 8:22 pm
by Hblade
Oh yeah!

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

PostPosted: Sun Jul 15, 2012 7:56 pm
by Fojam
im kind of confused on what you mean. would using an actor pointer in all of my functions that use actor vars fix it?

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

PostPosted: Sun Jul 15, 2012 11:00 pm
by skydereign
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.

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

PostPosted: Mon Jul 16, 2012 11:50 am
by Fojam
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