setDataBlock Faking space flight.
by RageO · in Torque Game Engine · 04/08/2010 (4:11 am) · 4 replies
Hi, Im messing with Torque and Im hitting a snag. First of all I realize that its not wise to change datablocks once created. However, here I am and here is what I am trying to accomplish.
I have .cs files for 2 flying vehicles. Both work I am attempting to change the roll parameter in the data block upon key press in order to have side thrusters (Like strafing)
Now My player is the war sparrow and when I use the setDataBlock(WarSparrow2) command in the game.cs on player creating it will change the data block so I have all of the syntax correct on that commmand.
I am attempting to use a function to change the data block but it just will not work. Frankly Im not sure quite where to put it either Ive tried it every where. I am using the tutorial.base example with editor etc...
Here is the script code I have. Any advice is greatly appreciated.
// Located in player.cs
function changePlayerDB(%client)
{
%player = getPlayer();
%player.setDataBlock(WarSparrow2);
}
moveMap.bindCmd(keyboard, q, changePlayerDB);
I have moved that everywhere. I have attempted different versions of
commandtoserver( %player.setDataBlock(WarSparrow2)); included in the move map command etc...
I just cannot get it to work unless I only put %player = getPlayer();
%player.setDataBlock(WarSparrow2); in the game.cs right after player creation...
I just want to be able to change the datablock on a key press.. Can some one tell me what I am doing wrong ?
I have .cs files for 2 flying vehicles. Both work I am attempting to change the roll parameter in the data block upon key press in order to have side thrusters (Like strafing)
Now My player is the war sparrow and when I use the setDataBlock(WarSparrow2) command in the game.cs on player creating it will change the data block so I have all of the syntax correct on that commmand.
I am attempting to use a function to change the data block but it just will not work. Frankly Im not sure quite where to put it either Ive tried it every where. I am using the tutorial.base example with editor etc...
Here is the script code I have. Any advice is greatly appreciated.
// Located in player.cs
function changePlayerDB(%client)
{
%player = getPlayer();
%player.setDataBlock(WarSparrow2);
}
moveMap.bindCmd(keyboard, q, changePlayerDB);
I have moved that everywhere. I have attempted different versions of
commandtoserver( %player.setDataBlock(WarSparrow2)); included in the move map command etc...
I just cannot get it to work unless I only put %player = getPlayer();
%player.setDataBlock(WarSparrow2); in the game.cs right after player creation...
I just want to be able to change the datablock on a key press.. Can some one tell me what I am doing wrong ?
#2
04/08/2010 (9:17 am)
Quote:I'm glad to see someone using setDataBlock rather than trying to change datablock memberspeople actually try to do that?!
#3
I was bouncing around so much and getting mixed up on what was where.
1 thing that was strange I had to make a separate function to use the commandtoserver(changerPlayerDB) then call that new function from the moveMap.bind command ??
It would not work calling that function directly from the moveMap command. I Im just not sure why this is. I thought I could add the commandtoserver in the moveMap command and be done with it but it would not work.
Either way thanks. Im moving on now. Im giving torque another chance. Ive made several games in DBP and Im used to making my own engine. But I like Torque and once I get my head around it Im sure its going to fit my needs.
Last question I am considering upgrading to torque 3d but before I do what are the differences from 1.5.2 and is the documentation any better ? Thats my biggest gripe with TGE I would love to have some decent reference files ready on the fly.
04/09/2010 (12:14 am)
Thanks Daniel! After some trial and error I got it right. You helped clear me up on the client/server side. Ive since created 2 separate cs files 1 for client 1 for server.This will help keep me a bit more organized.I was bouncing around so much and getting mixed up on what was where.
1 thing that was strange I had to make a separate function to use the commandtoserver(changerPlayerDB) then call that new function from the moveMap.bind command ??
It would not work calling that function directly from the moveMap command. I Im just not sure why this is. I thought I could add the commandtoserver in the moveMap command and be done with it but it would not work.
Either way thanks. Im moving on now. Im giving torque another chance. Ive made several games in DBP and Im used to making my own engine. But I like Torque and once I get my head around it Im sure its going to fit my needs.
Last question I am considering upgrading to torque 3d but before I do what are the differences from 1.5.2 and is the documentation any better ? Thats my biggest gripe with TGE I would love to have some decent reference files ready on the fly.
#4
07/03/2012 (5:52 pm)
Thank you Daniel I was having the same problem :D
Torque Owner Daniel Buckmaster
T3D Steering Committee
function serverCmdChangePlayerDB(%client) { %player = %client.player; %player.setDataBlock(WarSparrow2); }Then you'd need to call that from the client as followscommandtoserver('changePlayerDB');I *think* that's about right.
This should only ever go in default.bind.cs. You also don't bind the function that changes the player datablock - you bind a client-side function that tells the server to do something.
So the process goes somewhat like
-Bind a command to a key on the keyboard
-Client computer registers key press and calls command
-Command sends message to server saying 'hey I want to change datablocks'
-Server computer changes the player's datablock
-The changes are networked as usual and the client sees their datablock change
The script was working in game.cs because that stuff is run server-side. Adding binds to server-side scripts will never let them get called (try adding echo statements in your functions just to see if they're actually being called at all - helpful when debugging keyboard binding changes), and adding functions to client-side scripts that try to alter the game will be overridden by the server scripts (if you let clients change things willy-nilly then people can hack and cheat all they want).
Sorry for the somewhat incoherent response... it's past my bedtime :P. I haven't given you the solution, but hopefully you can see where it's going wrong. Also, I'm glad to see someone using setDataBlock rather than trying to change datablock members ;).