Game Development Community

Bug : CodeBlock::exec strange behaviour.

by Claude-Alain Fournier · in Torque Game Engine · 08/13/2004 (1:25 am) · 5 replies

Hi,

I implement GameConnection::onConnectRequest(...).

My problem is that the last argument is always empty.

I set the arguments in GameConnection.setConnectArgs(...) all is fine till the code reach "CodeBlock::exec(...)" in compiledEval.cc.

Somewhat when evaluating the arguments, I realise that the argc variable is one less than the passed argument. The value is changed in line 14 of the CodeBlock::exec function :

argc = getMin(argc-1, fnArgc); // argv[0] is func name

So when the arguments are evaluated the last one is always lost due to the default "%this" :

for(i = 0; i < argc; i++)
{
     StringTableEntry var = U32toSTE(code[ip + i + 6]);
     gEvalState.setCurVarNameCreate(var);
     gEvalState.setStringVariable(argv[i+1]);
}

Is that a bug ? or I do something wrong ?

Thanks in advance for you help.

CAF

#1
08/13/2004 (1:28 am)
Currently to get around that problem I set one more "dummy" parameter in setConnectArgs(...).
#2
08/13/2004 (8:53 am)
I'm not sure I follow. Can you show the code that you use to actually make the script call? You might have your argument conventions off a bit...
#3
08/13/2004 (10:38 am)
Ben,

I don't call directly that's part of the GameConnection object. In script I call the following to start connection :

%conn = new GameConnection(ServerConnection);
%conn.[b]setConnectArgs[/b]($pref::UserName::Name, $pref::UserName::Password); 
%conn.setJoinPassword($Client::Password);
%conn.connect($ServerInfo::Address);

Now the rest is part of the C++ objects :

In file gameConnection.cc, method : GameConnection::readConnectRequest(....)

You execute the following code :
connectArgv[0] = "onConnectRequest";
   char buffer[256];
   Net::addressToString(getNetAddress(), buffer);
   connectArgv[2] = buffer;

   const char *ret = Con::execute(this, mConnectArgc + 2, connectArgv);

I need to check the connection info with the player Database so I created a method GameConnection::onConnectRequest(%this, %address, %username, %pwd) in server/script/game.cs

Wait a minute, I think I just found the problem here :

const char *ret = Con::execute(this, mConnectArgc + 2, connectArgv);

should be

const char *ret = Con::execute(this, mConnectArgc + [b]3[/b], connectArgv);

Because you take the number of argument passed in setConnectArgs(...) and add the method name, the Id of the object and the server address (+ 3 arguments).

Unless I am completely bloto that's the problem.

Sometimes trying to explain to somebody make you solve it ;). Thanks for your help Ben :D

Regards,

CAF
#4
08/13/2004 (1:01 pm)
Hmm... Yeah, that looks right. That change ought to go into HEAD, I bet...
#5
08/17/2004 (2:02 pm)
And now it is.