Trouble getting syntax for Player::getPose()

There are no stupid questions, just stupid answers.
10 posts Page 1 of 1
Sir_Skurpsalot
Posts: 55
Joined: Tue Jan 28, 2020 6:32 pm
by Sir_Skurpsalot » Fri Feb 21, 2020 1:06 am
Ok I'm trying my first bit of scripting with torque, having come from unity and godot its quite a bit different. Right now I'm working on changing the way crouching and prone works so you have stance up and stance down keys that cycle you from standing down to prone and back up ala original ghost recon. echo($Player::getPose); does not return anything though, literally a blank space in the console. What is the correct syntax to get the players pose? I'm trying to call this from client/default.bind.cs. That's another thing with Torque... I have no idea where you can and can't access things from, or how other scripts access each other.
Azaezel
DEVGRU
Posts: 496
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Fri Feb 21, 2020 6:51 am
Alright, there's a couple ways to answer that, so we'll go through both of em for a nice 101 sample:

So if ya look at https://github.com/GarageGames/Torque3D ... .cpp#L6564, you'll notice it's referencing a player class instance. so what you'll want to do for that kind of thing is look up the objectID you'll usually find that kind of thing referenced either in a function player::someFunc(%this) or a function playerData::someDBfunc(%this,%obj) (where the second entry of %obj references the instance and the %this references the shared-data functionality)

next step, note that
https://github.com/GarageGames/Torque3D ... me.cs#L573 bolts a %client.player value onto a %client objectinstance created when you connect to a server (you're always connecting to a server) and effectively clones the objectid as a pointer to the object you're controlling, be that a player or a vehicle derivative. (should note it's entirely coincidental/convention that the %obj.player value shares the name of the class, just as it's entirely convention that the first var in a given callback method is usually tagged as %this)

third, given the above about 'you're always connecting to a server, even if you're hosting it just for yourself' note the format for
https://github.com/GarageGames/Torque3D ... ds.cs#L520
+
https://github.com/GarageGames/Torque3D ... led.cs#L94


so the net result of that all gives us the following snippet to plop in and verify for yourself:
function getMyPose()
{
    commandToserver('GetPlayerPose');
}

function serverCmdGetPlayerPose(%client)
{
   echo(%client.player.getPose());
}

part 2:


all that being said, keybind methods sent along %val as true for key poushed down and false for it up, so flipping crouch from a constant press and release to a toggle's as simple as
function doCrouch(%val)
{
    if (%val)
        $mvTriggerCount3++;
}
Duion
Posts: 1622
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Fri Feb 21, 2020 5:33 pm
Before you try to make your complicated solution work, you should check if there is an easier solution or if what you are trying to do even makes sense.

First I would say having to cycle through duck, pron and standing is a bad solution, having a key for each is much simpler to use for the player.

Second if you want things to just toggle instead of having to hold down the button, this already exists in the engine, you just have to change it, but Azaezel already told you how that works.

And please try to avoid solutions where you "get player pose" and stuff and make functions based on that, since those things really like to produce glitches and you have to put in "get player pose" functions all over the scripts to avoid those, which just costs you lots of unnecessary work and performance.

So forget everything and just flip it from constant press to toggle as Azaezel said. All the trouble just to save one button is not worth it, modern games just do it because console peasants don't have enough buttons and I just noticed your solution would not even save a button, since to cycle through the positions you need two buttons and that is exactly what you need for duck and prone. So I don't see any advantages in that cycle through solution, it just makes everything more complicated to program and more complicated for the player to use.
Sir_Skurpsalot
Posts: 55
Joined: Tue Jan 28, 2020 6:32 pm
by Sir_Skurpsalot » Fri Feb 21, 2020 11:01 pm
Thanks for the responses.
Torque is pretty strange, so as long as you start a function's name with serverCmd you can call it from any script, and it has access to %client?
So the code snippet works, but now that I've got that I want to change it so it returns the pose to the function that called it, but it is not working.
If I change the server function to:
function serverCmdGetPlayerPose(%client)
{
	return %client.player.getPose();
}

and then try to:
 echo(commandToserver('GetPlayerPose'));
I get the error:
scripts/client/default.bind.cs (292): Call to commandToServer in stanceDown uses result of void function call.
Why is it void?
Azaezel
DEVGRU
Posts: 496
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Sat Feb 22, 2020 1:45 am
nah, commandoserver('somemethod') + serverCMDsomemethod it's what's known as an RPC or remote protocol command. just a way of saying to your aps conneciton class to transmit 'hey, run this method on the server', tagging methods to start with serverCMD gives it a shorter list of commands to hunt through to find and execute when it that side of the connection goes to figure out what you're requesting it does. there's similar for commandtoclient('SomeMethod2')+clientcmdSomeMethod2 for servers to tell clients to run commands that aren't built direct into the source.

"uses result of void function call" is pretty much what it says on the tin. the commandToserver method in and of itself is not returning anything, just going 'hey, other end of this network, do this'. so to further expand our in/out given the above:
function getMyPose()
{
    commandToserver('GetPlayerPose');
}

function serverCmdGetPlayerPose(%client)
{
    %pose = %client.player.getPose();
    commandToclient(%client,'GotPlayerPose',%pose);
}
function clientcmdGotPlayerPose(%pose)
{
    echo("my pose is " @ %pose);
}
which will let you hit ~, plug that
getMyPose()
into the console, and get back your pose even if you're on somebody else's server (provided they have that serverCmdGetPlayerPose defined their end)
Duion
Posts: 1622
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sat Feb 22, 2020 2:43 am
Now if you want to make it even more complicated you implement all methods and let the player chose in options which one he wants to use.
fLUnKnhaXYU
Posts: 164
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Sat Feb 22, 2020 5:19 am
using $mvTriggercount4++ , placing the character in prone , if you use the getControlObject().getPose() , or the like , will return " prone " but , if while in prone you also set $mvTriggercount2++ , your character begins jumping and the pose will be "standing" and after another $mvTriggercount2++ (stop jump) will return to "prone" . So . I guess that while prone + jumping that an upPose would not result in crouch yet , a downpose should result in crouch . anybody got change for 2 cents ?

Sir_Skurpsalot , I don't know if you can pass arguments to those key bind functions other than the one for %val . I see in the demo that some gamepad binds use "if" statements with serverConnection methods , but I don't have one , and I haven't messed with them . But i cant get serverconnection.getID() so , IDK .
Sir_Skurpsalot
Posts: 55
Joined: Tue Jan 28, 2020 6:32 pm
by Sir_Skurpsalot » Sat Feb 22, 2020 2:16 pm
Azaezel - ok so return statements do not work with server functions is what you are saying?

I found a way to do this without bothering with any server functions, just made a global variable to track pose without actually getting the pose. Any downside
to doing it this way from a client-server relation perspective?
$pose = "Standing";
function stanceDown(%val)
{
	if (%val)  
   {   	   	   
   	  if($pose $= "Standing")
   	  {
   	   $mvTriggerCount3++;
   	   $pose = "Kneeling";
   	  }
   	  else if ($pose $= "Kneeling")
   	  {
   	   $mvTriggerCount3++; 
   	   $mvTriggerCount4++;
   	   $pose = "Prone";
   	  }  	  
   }
}

function stanceUp(%val)
{
	if (%val)  
   {   	   	   
   	  if($pose $= "Kneeling")
   	  {
   	   $mvTriggerCount3++;
   	   $pose = "Standing";
   	  }
   	  else if ($pose $= "Prone")
   	  {
   	   $mvTriggerCount4++;
   	   $mvTriggerCount3++;
   	   $pose = "Kneeling";
   	  }   
   }
}
Azaezel
DEVGRU
Posts: 496
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Sun Feb 23, 2020 2:47 am
Azaezel - ok so return statements do not work with server functions is what you are saying?

I found a way to do this without bothering with any server functions, just made a global variable to track pose without actually getting the pose. Any downside
to doing it this way from a client-server relation perspective?
No, I'm saying return statements don't even make sense when you're firing off a command from one machine to another (or mimicking doing so to save yourself migraines down the line trying to hunt down why guy A sees one thing and guy B another). Its a one way communication each way. Hence that middle method from example 2.

In a competitive environment you'll want to lean on the server more as referee. If you don't particularly care about that kinda thing, by all means, do what makes the most sense to you. Personally, I'd probably just alter the source end to cut down on the script kiddies hacking a short circuit into it, but you'd mostly asked about how to parse script, so that's been the focus.
Sir_Skurpsalot
Posts: 55
Joined: Tue Jan 28, 2020 6:32 pm
by Sir_Skurpsalot » Tue Feb 25, 2020 10:16 pm
Ok, gotcha. Thanks for the help
10 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests