Game Development Community

Sorry, this is about "Unknown command" error

by Matthew W · in Torque Game Engine · 04/27/2008 (3:09 pm) · 1 replies

Edit: "Where are the experts?" is rude, im so sorry yall. :(

Here is my code

moveMap.bind( mouse, button0, useButton0);

//by matthew
function useButton0(%val) {

   
   if (%val) {
      %camera = $Pref::Player::CurrentFOV;
      %place = PlayGui::onMouseDown(localClientConnection.getCameraObject());
      1785.setMoveDestination(%place, true);
   
}
}

When i click the left mouse button on the terrain i get a message in the console like this
Quote:
tutorial.base/client/playGui.cs (34): Unknown command getMouse3DVec.
Object (1783) Camera -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
tutorial.base/client/playGui.cs (37): Unknown command getMouse3DPos.
Object (1783) Camera -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
tutorial.base/client/playGui.cs (39): Call to commandToServer in onMouseDown uses result of void function call.
tutorial.base/client/default.bind.cs (136): Unknown command setMoveDestination.
Object (1785) Camera -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
tutorial.base/client/playGui.cs (39): Call to commandToServer in onMouseDown uses result of void function call.

i'm trying to use the "Object selection in Torque (v1.2 onward)" resource. Why would it say getMouse3DVec is an unknown command?

#1
04/28/2008 (12:26 pm)
Ok, it looks like you need some help/clarification on a few things here. First off, let's start with reading the log and interpreting that for clues:
Quote:tutorial.base/client/playGui.cs (34): Unknown command getMouse3DVec.
Object (1783) Camera -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
tutorial.base/client/playGui.cs (37): Unknown command getMouse3DPos.
The bold part there is the main "clue" to this entry. You have called the onMouseDown function of the PlayGui object. Iniside of the playGui.cs script, on line 37 (that's whats in the parenthesis there) that script is attempting to call a function getMouse3DPos. For whatever reason, in your build that function is missing. It appears to be trying to find that function on the Camera object. Perhaps you missed integrating some code from the resource?

From there the error "cascades" (or causing further related errors). Because the call to onMouseDown fails, and doesn't return a value then your %place variable has nothing in it.

Now this line of code is a "don't ever do" kind of thing in Torque:
Quote:1785.setMoveDestination(%place, true);
Looks like you are calling a function based on an object's Sim ID that has been hard-coded. You must never call a function with a hard-code Sim ID. Sim ID's get re-assigned each time the game is run, so you can never be sure that object 1785 will ever be what you think it is. In a few runs of the game it might be the Camera object, later it might be the Player, or another time it might be a Tree, or a Building. You can never be sure. Secondly, if the code you quote above is from your default.bind.cs script, then your code has some Client-Server problems. If you're writing your game to be Single-player only, then you're okay.

In a Client-Server multiplayer situation, like in Torque, the Client should only ever handle things that don't "really matter" as far as the game is concerned. The Client is for handling inputs from the person playing the game (like mouse clicks) and for rendering the game on their screen. Beyond that, any of the actual "gameplay" stuff should be handled on the server. What's my point? A call to setMoveDestination is something that should really be done on the Server. So, if you want to build your code to "behave" in a Client-Server setup, you should do that setMoveDestination call on the Server. The previous two lines are fine on the Client as they have to do with handling inputs (mouse clicks) but once you have figured "where" in the game world the user has clicked, that info should be passed off to the Server for it to handle the actual move.

You may be asking, "Fine, how do I do this?" Here's how. You need to change your code to make a "remote functional call" like this:
commandToServer('MovePlayer', %place);
That will pass the %place information off to the server. Now you'll need to write a function somewhere in your server scripts that looks like this:
serverCmdMovePlayer(%client, %place)
{
   %client.player.setMoveDestination(%place, true);
}
When commandToServer is called, you pass in the name of a function ("MovePlayer") in this case. On the server it will look for a function with "serverCmd" in front of that name (see how the server function is called "serverCmdMovePlayer"). All commandToServer functions pass the client Connection object as the first parameter (see %client there?). If you have not modified it in game.cs a reference to the players avatar should be stored in %client.player, that will contain the Sim ID of the Player object for this particular session of the game, and you can be sure that it is always up to date. That way you don't have to hard-code an ID like you have above.

So, that was a bit of a lengthy response, but I wasn't sure how much you needed to know, and maybe someone else with a similar question will learn something too.