Game Development Community

Creating a new function inside a game mode

by Jonas · in Torque 3D Professional · 04/20/2011 (2:37 am) · 10 replies

Hi!

This is a problem i have no idea how and why it appears:

Inside the gameDM.cs file resides all of the game mode functions for that game mode.
Alot of these functions call other functions in this manner: %game.preparePlayer(%client);
without any problem.

If i however create a new function such as this one:

function DeathMatchGame::***Select(%game, %client)
{
$***Select = 0;
$***Select = 1;
$***Select = 1;
$***Select = 0;
%game.Weapon_Check(%client);
}

NOTE: Stars are just there to block out names.

This function even though the function called weapon_check exists within the confines
of this file and game mode with "DeathMatchGame::" it cannot be found.
This problem appears when i try to call a function that was there from when the file was generated to.

this function once called give me the following error:

Scripts/server/gameDM.cs (435): Unable to find object: '' attempting to call function 'weapon_check'

I am certain i have missed something since this only happens in game modes i am just not sure what
please point me in the right direction.

Best regards
Jonas

About the author

Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.


#1
04/20/2011 (5:39 am)
It's pretty hard to tell exactly what's the problem with your code without the whole or more code than given.

So DeathMatchGame::weapon_check already exist ?

Are you having any kind of compile error ?
#2
04/20/2011 (6:20 am)
Some more info:
I am currently using the 'binary version' or in other words source code is standard and unmodified.

The components around Gamecore is basically unmodified.

to clarify the problem:
Before i tried to make a servercmd to the game mode in question and it finds the exact function i call for(dosent matter which one) but if that function in turn try to call another function it gives me the same message as stated above.

test i made:
i create a function(lets call it TEST for now) with a echo command in it and i call it from the prepareplayer function which is a default function in the gamemode. The function is called succesfully, even when i call a second fucntion from TEST it works fine.

I create a function called TEST again and call if from another function called TEST2 that is not a standard function of the game mode. I will then get the same message as above.

More code:

function DeathMatchGame::***Select(%game, %client)
{
$***Select = 0;
$***Select = 1;
$***Select = 1;
$***Select = 0;
%game.Weapon_Check(%client);
}

function DeathMatchGame::Weapon_Check(%game, %client)
{
$***_Select_ED = $***_Select;
$***Select_ED = $***Select;
$***Select_ED = $***Select;
$***Select_ED = $***Select;
echo("weapon check");
echo("Check:", $***Select_ED);
}

function DeathMatchGame::WeaponSelectSend(%game, %client)
{

if($***_Select_ED == 1)
{
echo("You picked ***");
}

if($***Select_ED == 1)
{
echo("You picked ***");
}

if($***Select_ED == 1)
{
echo("You picked ***");
%game.preparePlayer(%client);
}

if($***Select_ED == 1)
{
echo("You picked ***");
}

if($***_Select_ED == 0 && $***Select_ED == 0 && $***Select_ED == 0 && $S***Select_ED == 0)
{
echo("Waiting for input!");
}
}

NOTES: The system code above works perfectly the only part that dosent is the %game. calls i added onces i moved it into the game mode.

Best regards
Jonas
#3
04/20/2011 (6:36 pm)
How are you calling %game in your game mode code ?
#4
04/20/2011 (10:38 pm)
Argh - too many ********************************************************.
#5
04/21/2011 (12:18 am)
Hehe im sorry for the stars.

"How are you calling %game in your game mode code ?"

Im afraid i don't quite follow, however all code surrounding
this issue is basically unmodified including the game mode is standard (file called gameDM.cs in a "full generated project").

Before we move further into the issue i just wanna ask if i make a new function in a game mode as shown above, do i need to make any other function in any other file or should it work right of the bat?

I just find it odd, i have been around the block for a while and in general terms know how it all works but game modes isent that simple it seems.

Best regards
Jonas
#6
04/21/2011 (12:55 am)
The thing about the game-type system to remember is that it uses a ScriptObject to "hold" the game-type "object". This is what the parameter %game should be referencing. Throw in some echo's checking all parameters and their values (or step through the code with your IDE) to make sure everything getting passed as expected.

Need to know how you're initially calling the check and send methods seen above. If they're not getting the correct argument information then the whole series of calls within them will fail. You may be needing to call them with the ScriptObject's name... depending on how you're getting to these functions.
#7
04/21/2011 (3:44 am)
Ah i see i will try to provide the entire chain down below:

The function chain begins with a gui file built up on buttons each button have its own set of select variables that equips the character with the right weapon:

function DeathMatchGame::***Select(%game, %client)
{
$***Select = 0;
$***Select = 1;
$***Select = 1;
$***Select = 0;
%game.Weapon_Check(%client);
}

This function is called with a button press in the gui(command)
which is the following: DeathMatchGame::***select();

With this weapon_check is called via the **select function
which later on feeds into: WeaponSelectSend and that function
in turn calls %game.preparePlayer(%client);.

I hope it clarifies the problem

NOTE: all this was tested in another place before moving it over to gameDM.cs so im almost 100% sure its related to some part of it not
really beind adapted for game mode functionality.

Cheers!
Jonas
#8
04/21/2011 (2:13 pm)
Try calling ***select from your gui(command) as Game.***select. Chances are it's not recognizing the namespace (as it's not an actual class namespace outside of the Game ScriptObject) and you're not getting correct values when attempting to further pass along the %game parameter.

#9
04/22/2011 (12:04 am)
Viva La community!

Works great now thanks for all the help its greatly appreciated!

Best regards
Jonas
#10
04/22/2011 (12:06 am)
Viva La community!

Works great now thanks for all the help its greatly appreciated!

Best regards
Jonas