Game Development Community

Setting Gui object position problem

by Jon Uhal · in Torque Game Engine · 03/19/2006 (6:01 pm) · 1 replies

I have been trying to get this to work for a week now. This is probably a ridiculous problem and I really hope there is a good explanation for this because it's been driving me crazy.

In Torquescript, I have been trying to concatenate two variables that are storing the calculation of some simple math. When I go to save the values in the .position value of the GUI control in order to move it around the screen. This is set on a schedule to happen every 100 milliseconds. Here is my function:

function updatePlayerPosition()
{
    if(MapHud.unschedule == 1)
    {
        return;
    }
    
    echo(" BEFORE: player (" @ MapHud.playerLocation @ "); display (" @ MapDisplay.extent @ "); mapPosition (" @ MapHud.position @ ")");
    %playerX = getWord(MapHud.playerLocation, 0);
    %playerY = getWord(MapHud.playerLocation, 1);
    %displayX = getWord(MapDisplay.Extent, 0);
    %displayY = getWord(MapDisplay.Extent, 1);
    echo("EXTRACT: player (" @ %playerX SPC %playerY @ "); display (" @ %displayX SPC %displayY @ ")");
    %posX = (%displayX / 2) - %playerX;
    %posY = (%displayY / 2) - %playerY;
    echo("BMAPHUD: pos (" @ %posX SPC %posY @ ")");
    %position = %posX SPC %posY;
    echo("   POS: pos (" @ %position @ ")");
    MapHud.position = %position;
    echo("AMAPHUD: pos (" @ MapHud.position @ ")");
    schedule(100, 0, "updatePlayerPosition");
}

Here is some sample output:

BEFORE: player (274.167 457.769); display (150 150); mapPosition (-199 75)
EXTRACT: player (274.167 457.769); display (150 150)
BMAPHUD: pos (-199.167 -382.769)
   POS: pos (-199.167 -382.769)
AMAPHUD: pos (-199 75)

I have tried many different scenarios of setting the MapHud.position variable. This is my latest attempt, by first storing the value I want to save as %position, and then saving that into MapHud.position. My problem is, that whenever I try to change the MapHud.position value, only one value will ever get changed. In the output you can see that %position is set to (-199.167 -382.769) but in the AMAPHUD step, only the X value has changed (-199 75). I have even tried doing the SPC concatentation directly to MapHud.position (MapHud.position = %posX SPC %posY;) and tried treating the MapHud.position value as an array (MapHud.position[0] = %posX; MapHud.position[1] = %posY;). All attempts have netted the same result, where only one value has changed, either the X value or the Y value.

I have made so many attempts at getting this to work that I'm afraid a bug exists in the engine when trying to set a value, but I would like to try to figure out why I am unable to completely change the MapHud.position value...

#1
03/20/2006 (10:26 am)
Found a solution in another post.

http://www.garagegames.com/mg/forums/result.thread.php?qt=31036