Game Development Community

Issues with "turn-based" function

by Dan Dias · in Torque Game Builder · 10/06/2005 (11:08 pm) · 1 replies

I've searched the forums and have found a few things similiar to this... but nothing exactly like it.
Now this might be a ridiculous way to do things... so don't laugh, please! If you know of a better way to do it, feel free to suggest it.

I have "units" (objects) created on the scene via their respective functions. They get created with certian variables unique to them, of course. One of which tells if it's their turn or not. So I made this function to toggle that variable when their turn is up and again when it's done.
function switchTurn(%unit)
{
  if (%unit.turn == false)
  {
    $unit = %unit;
    $unit.turn = true;
    $unit.moved = 0;
    $unit.actionPhase = true;
    $unit.movePhase = true;
    for(%c = 0; %c <= $unit.maxMove ; %c++)
    {
      createMoveMarker(getWord($unit.getPosition(),0)-10 SPC getWord($unit.getPosition(),1));
    }
    return;
  }
  if (%unit.turn == true)
  {
    %unit.turn = false;
    %unit.moved = 0;
    return;
  }
}
I need this to be used for each unit and I don't want to have to create a function for each object because it also deals with parts of the system that have (almost) nothing to do with the objects. (such as how many turns have passed, stuff like that)
The problem I'm having is that %unit should get assigned to $unit (which is the current unit who's turn it is.) Now, shouldn't I be able to access $unit.turn which would be the object I passed to it. Instead (as I'm sure you're saying "of course!") it's only giving me access to the variables I set after I assign %unit to $unit.
Thanks in advance!

#1
10/09/2005 (11:07 pm)
So it turns out it was a problem elsewhere when I set the object sent to the function, just needed a fresh look after a few days away. Live and learn!