Game Development Community

Old Strategy Tutorial

by Adam Robinson · in Torque Game Builder · 03/22/2008 (7:15 am) · 8 replies

Hiyas,
Been playing with the old strategy tutorial and there is one thing i just cant get to work and thats getting the
units to move on right click. When i right click i get the error of (78): Unknown command OnRightClick.

Is this because things have changed since that tutorial was created or perhaps ive done something wrong? I have searched the forums and what not and cant find anything to help me. Im not a programmer as such and i have everything else basically working and this thing has me stumped if anyone could head me in the right direction it would be appreciated.

cheers
Adam

#1
03/22/2008 (8:20 am)
Can you post your code where the error occurs (line 78 of the file by the looks of things)? I hav't done the tutorial myself so I don't know sorry!
#2
03/22/2008 (8:29 am)
Yeh line 78 right at the bottom..

function processAction(%worldPos, %mode)
{
   // get the count of objects selected
   %count = Selections.getCount();
   
   // if we have more than one object selected then we store that we have
   // multiple selections
   if(%count > 1)
   {   
      %multiple = true;
   } else
   {
      %multiple = false;
   }
   
   // here we loop through all of our selections
   for(%i=0;%i<%count;%i++)
   {
      // if we have a multiple selection we want to generate some offset points
      // so when we move a group of units they won't go to the same spot...
      // formation integration would go in here, but right now a simple
      // offset works for testing purposes
      if(%multiple)
      {
         // grab and divide the world positions as well as the offsets so we
         // can generate some -very- simple position offsets
         %worldX = getWord(%worldPos, 0);
         %worldY = getWord(%worldPos, 1);
         %offsetX = getWord($posOffset[%i], 0) + getRandom(0,2);
         %offsetY = getWord($posOffset[%i], 1) + getRandom(0,2);
         
         // lets peice together the new position
         %pos = (%worldX += %offsetX) SPC (%worldY += %offsetY);
      } else
      {
         // if this is a single selection we want the object to go
         // where we clicked
         %pos = %worldPos;
      }
      
      // lets grab a list of all objects at the area clicked so we can pass this
      // to the object for its own use
      %objList = $strategyScene.pickPoint(%worldPos);
      
      // we store the object we're currently looping through and pass it
      // information the object might need
      %obj = Selections.getObject(%i);
      %obj.OnRightClick(%pos, %mode, %objList);
   }
}
Thanks
Adam
#3
03/22/2008 (9:35 am)
I guess it means that the object %obj does not have a OnRightClick method. Try adding in a default method and seeing if this gets rid of the error:

t2dSceneObject::OnRightClick(%this,%pos,%mode,%objList)
{
      echo(%this.getID());
}

If the error is because no such method exists, which i guess it is, this will print out the ID of the object that doesn't have the method.
What object classes do have a OnRightClicked method?
#4
03/22/2008 (11:44 am)
Maybe you didnt enabled useObjectMouseEvents() on that object. You can do it from level editor.
#5
03/22/2008 (12:00 pm)
I dont think that would matter, this isn't a mouse callback method, it's just a regular one.
#6
03/22/2008 (8:40 pm)
Looking further is OnRightClicked even a usable method? Should i be using OnRightMouseDown?

Thanks
Adam
#7
03/23/2008 (1:40 am)
Like Tom Perry said, OnRightClicked() is some regular custom function. We dont have the entire code, so we dont know how they imagined that should work.

Maybe the ::OnRightMouseDown() event is calling some custom OnRightClicked() function, and sometimes it is needed to call that action independetly, not from ::OnRightMouseDown().

I suppose its something like:
"in this case, we can imitate rightMouseClick", OR
"before we execute rightMouseClick, you must calculate a bunch of things, and THEN we do simple rightMouseClick"
#8
03/23/2008 (3:52 am)
Milan and Tom,
Yep your right sorry guys i got it working by just creating a default method like Tom said. I even had to create a default ::moveToLoc and thats atleast got me able to direct my one sprite via the right click.

As it is the units(soldier, worker etc etc) and functions are all in one *.cs file i think ill break em down into a datablock file and work the way the adventure kit does. At least for now ive got my basic actions happening.

Im not building a full on RTS but its good base to create a top down Space ship command type of game. Select ships and direct them, attack, defend etc etc

Thanks guys
Adam