Calling spawn from a gui
by Jonas · in Torque 3D Professional · 05/16/2011 (5:57 pm) · 8 replies
Hey!
I had a thread almost like this not far back but i have gotten into some trouble
in the final stage of fully implementing the system.
Basically i have it so when your dead and your camera gets unhooked and you can look
around your corpse you get a GUI instead of a spawn when you press "FIRE" (this is the
same system found in:http://www.garagegames.com/community/forums/viewthread/125570 but another
part of it aka weaponselectsend)
This is the error i get when i press spawn:
Scripts/server/gameDM.cs (410): Unable to find object: '' attempting to call function 'setControlObject'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'setInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'maxInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'setInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'mountImage'
I am almost a 100% certain that this is a result of a syntax error/ class namespace error as was pointed out in the last thread, i just cant see it and need another eye on it.
this is the files/functions involved from start to finish:(NOTE: this time i striped some of the data thats totally irrelevant hopefully there will be no *stars*)
TheGui.gui file:
button command: game.weaponselectsend();
GameDM.cs file:
function DeathMatchGame::WeaponSelectSend(%game, %client)
{
if($****Select_ED == 1)
{
echo("You picked ****!");
%game.prepareplayer(%client);
canvas.popDialog(TheGui);
}
}
camera.cs file:(i dont think the error is here since the error excists out side of this file on other tests)
function Observer::onTrigger(%this,%obj,%trigger,%state)
{
// state = 0 means that a trigger key was released
if (%state == 0)
return;
// Default player triggers: 0=fire 1=altFire 2=jump
%client = %obj.getControllingClient();
switch$ (%obj.mode)
{
case "Observer":
// Do something interesting.
case "Corpse":
// Viewing dead corpse, so we probably want to respawn.
canvas.pushDialog(Thegui);
// Set the camera back into observer mode, since in
// debug mode we like to switch to it.
%this.setMode(%obj,"Observer");
}
}
Extra notes:
1: Why line 410 error shows in the gamemode itself is because i moved the full spawnplayer function there.
2: Loadout can be called the "usual way" so its nothing wrong with the LO itself
Best regards
Jonas
I had a thread almost like this not far back but i have gotten into some trouble
in the final stage of fully implementing the system.
Basically i have it so when your dead and your camera gets unhooked and you can look
around your corpse you get a GUI instead of a spawn when you press "FIRE" (this is the
same system found in:http://www.garagegames.com/community/forums/viewthread/125570 but another
part of it aka weaponselectsend)
This is the error i get when i press spawn:
Scripts/server/gameDM.cs (410): Unable to find object: '' attempting to call function 'setControlObject'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'setInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'maxInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'setInventory'
Scripts/server/gameDM.cs (269): Unable to find object: '' attempting to call function 'mountImage'
I am almost a 100% certain that this is a result of a syntax error/ class namespace error as was pointed out in the last thread, i just cant see it and need another eye on it.
this is the files/functions involved from start to finish:(NOTE: this time i striped some of the data thats totally irrelevant hopefully there will be no *stars*)
TheGui.gui file:
button command: game.weaponselectsend();
GameDM.cs file:
function DeathMatchGame::WeaponSelectSend(%game, %client)
{
if($****Select_ED == 1)
{
echo("You picked ****!");
%game.prepareplayer(%client);
canvas.popDialog(TheGui);
}
}
camera.cs file:(i dont think the error is here since the error excists out side of this file on other tests)
function Observer::onTrigger(%this,%obj,%trigger,%state)
{
// state = 0 means that a trigger key was released
if (%state == 0)
return;
// Default player triggers: 0=fire 1=altFire 2=jump
%client = %obj.getControllingClient();
switch$ (%obj.mode)
{
case "Observer":
// Do something interesting.
case "Corpse":
// Viewing dead corpse, so we probably want to respawn.
canvas.pushDialog(Thegui);
// Set the camera back into observer mode, since in
// debug mode we like to switch to it.
%this.setMode(%obj,"Observer");
}
}
Extra notes:
1: Why line 410 error shows in the gamemode itself is because i moved the full spawnplayer function there.
2: Loadout can be called the "usual way" so its nothing wrong with the LO itself
Best regards
Jonas
About the author
Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.
#2
What i don't get is if my: game.weaponselectsend();/%game.prepareplayer(%client);
need the client.player parameter how come in the case of the camera file it only uses the parameter %client? Or is there something i miss understood?(english is my second language)
Best regards
Jonas
05/18/2011 (6:02 am)
I think i get what your saying and it makes sense.What i don't get is if my: game.weaponselectsend();/%game.prepareplayer(%client);
need the client.player parameter how come in the case of the camera file it only uses the parameter %client? Or is there something i miss understood?(english is my second language)
Best regards
Jonas
#3
It's the loadout() function that is needing the %client.player object since it has to give items to the newly spawned player. If the client isn't known by preparePlayer() then the loadOut() call, which is made from preparePlayer(), will fail since the player object is a property of the client.
05/18/2011 (10:35 am)
Oops, sorry, I misspoke about that. You only need to make the client known to the preparePlayer() function, which is what your example was missing when called from weaponselectsend(). It's the loadout() function that is needing the %client.player object since it has to give items to the newly spawned player. If the client isn't known by preparePlayer() then the loadOut() call, which is made from preparePlayer(), will fail since the player object is a property of the client.
#4
But the error is still present. I have checked how prepareplayer is called via other functions and i can't find anything wrong the only difference is that i am using a GUI.
I noticed something upon further testing:
When i press the "FIRE" button when the character is dead and i minimize the gui i can "Fly" around like in the editor. Could this be a source of a error?
Best regards
Jonas
05/19/2011 (7:09 pm)
I see, i tested fixing the error (changing game.weaponselectsend(); to game.weaponselectsend(%client);)But the error is still present. I have checked how prepareplayer is called via other functions and i can't find anything wrong the only difference is that i am using a GUI.
I noticed something upon further testing:
When i press the "FIRE" button when the character is dead and i minimize the gui i can "Fly" around like in the editor. Could this be a source of a error?
Best regards
Jonas
#5
The flying camera is simply your control object becoming detached from a player object and instead of being locked to corpse orbit mode it becomes a free camera allowing you to move around - not really an error just something you'll have to take into account and write some code for.
05/19/2011 (7:16 pm)
In that case, inside your gui script right before weaponSelectSend() is called you need to determine who the client is. I had assumed that the client was already known since you're dealing with guis.The flying camera is simply your control object becoming detached from a player object and instead of being locked to corpse orbit mode it becomes a free camera allowing you to move around - not really an error just something you'll have to take into account and write some code for.
#6
As you might already have thought its my first time dealing with the gui/game mode combination.
Best regards
Jonas
05/19/2011 (7:33 pm)
Could you please clarify how i would make the client known?As you might already have thought its my first time dealing with the gui/game mode combination.
Best regards
Jonas
#7
A single player game could take an easier shortcut.
In my game I spawn as a camera/observer onTrigger event (always knowing who the client is and always having a control object) using preferences (the selectTeam/selectClass/selectEquipment guis change the stored preferences)... so there are several ways to accomplish the same end-goal.
05/19/2011 (8:33 pm)
The simplest way since I don't know what you have in your gui is to do a commandtoserver call which will in turns call weaponSelectSend(). The act of the client sending the commandtoserver automatically lets the server know who the client is that needs to know whatever command just got sent. // button command on gui Command = "needToSpawn";
// client side function
function needToSpawn()
{
commandtoserver('prepareSpawn')
}// server side function
function serverCmdprepareSpawn(%client)
{
game.weaponselectsend(%client);
}A single player game could take an easier shortcut.
In my game I spawn as a camera/observer onTrigger event (always knowing who the client is and always having a control object) using preferences (the selectTeam/selectClass/selectEquipment guis change the stored preferences)... so there are several ways to accomplish the same end-goal.
Associate Michael Hall
Distracted...
function DeathMatchGame::WeaponSelectSend(%game, %client) { if($****Select_ED == 1) { echo("You picked ****!"); %game.prepareplayer(%client); // who is the client/player object? canvas.popDialog(TheGui); } }The game ScriptObject is doing it's thing but preparePlayer() is also expecting a second parameter which isn't supplied, thus the Unable to find object: '' errors. This second parameter should be the player object being spawned for the client: client.player.