Calling script functions from c++
by Anders Jacobsen · in Torque Game Engine · 01/18/2005 (10:08 am) · 12 replies
I can't seem to find this anywhere, is it possible from gameConnection.cc
to call up a function in a script (server side) and retrieve a string?
More specifically I see it retrieve $Pref::Server::Password in
the connection request function.
I assume the entire server and scripts are loaded at this point in the code.
to call up a function in a script (server side) and retrieve a string?
More specifically I see it retrieve $Pref::Server::Password in
the connection request function.
I assume the entire server and scripts are loaded at this point in the code.
#2
01/18/2005 (10:14 am)
Con::executef(1, "yourfunction");
#3
01/18/2005 (10:21 am)
Thanks. Another thing that bugs me... Is it possible to set up objects in the c++ sense in scripts? I see functions in script appear to be "global" in the sense of the $ and % type variables, or will I have to write them in c++ instead and call their members from scripts?
#4
be Con::executef(1, "yourfunction", variable); ?
01/18/2005 (10:26 am)
Oh btw, I also need to pass a variable to my script function, would thisbe Con::executef(1, "yourfunction", variable); ?
#5
You need to increment the value shown before your function name if you want to pass a function, or TGE will crash.
It's basically your number of arguments + the function.
For example:
Con::executef(1, "yourfunction");
Con::executef(2, "yourfunction", var1);
Con::executef(3, "yourfunction", var1, var2);
01/18/2005 (10:36 am)
Yes. But..You need to increment the value shown before your function name if you want to pass a function, or TGE will crash.
It's basically your number of arguments + the function.
For example:
Con::executef(1, "yourfunction");
Con::executef(2, "yourfunction", var1);
Con::executef(3, "yourfunction", var1, var2);
#6
Hmm ran into another small problem...
Seems I will only have the pass available.
How'd I retrieve the accompanying user name? I assume that has
been passed to server before the password. (Based on what I can see in the code)
01/18/2005 (10:44 am)
Ok thanks :)Hmm ran into another small problem...
Seems I will only have the pass available.
How'd I retrieve the accompanying user name? I assume that has
been passed to server before the password. (Based on what I can see in the code)
#7
01/18/2005 (10:45 am)
My guess is it's in mConnectArgv, but how do I make sure I get the correct one?
#8
01/18/2005 (11:29 am)
Have you read the documentation yet? It's getting really good, and answers your question pretty directly. In particular, you should read the scripting docs, which go into quite a bit of detail on interfacing between script and the engine, and how scripts are handled in the engine.
#9
01/19/2005 (8:36 am)
Okay, thanks. I'll take another read through.
#10
Any tips/tricks on how to find out?
01/22/2005 (11:04 am)
Still doesn't tell me what mConnectArgv in gameConnection.cc should contain. There wasn't much comments in there and I soon fell off track while trying to track the player name sent. I'm not even sure I was tracking that ;)Any tips/tricks on how to find out?
#11
01/22/2005 (4:12 pm)
It's just like the parameters for main() - an array of pointers to strings.
#12
01/23/2005 (10:22 am)
I don't remember the exact file/function they are set in, but do a quick search for "connect" in your client directory--nearby, you'll probably see a call to something similar to "setConnectArgs", which is simply a wrapper to add in your args to the connect request string sent by the client to the server. When we modified ours, we did have a bit of difficulty figuring out exactly how the connect args were being ordered, so you may first want to echo out the values of the variables on the client side, and also on the server side once the connect string is decoded, so you can keep things in sequence.
Torque Owner Anders Jacobsen