Author Topic: Eval Broken?  (Read 2955 times)

I'm making an event that uses eval. You type something in the text box, then you activate the brick or whatever you'd like to use. I just don't get why this doesn't work. This is for personal use and I do not plan on releasing this. Here's the code.
Code: [Select]
registerOutputEvent(fxDTSBrick,EvalEvent,"string 200 200");

function fxDTSBrick::EvalEvent(%this, %arg1, %client)
{
%evalarg = %arg1;
echo("attempting eval");
if(%evalarg $= "")
{
echo("no args");
return;
}
if(%client.isSuperAdmin)
{
echo("is super admin");
eval(%evalarg);
echo("the arg is");
echo(%evalarg);
}
%evalarg = "";
return;
}
This gives an "error syntax input" in the console at the point where it evals. Any help?

"syntax error in input" means the eval failed.

What is it you are trying to eval?

Code: [Select]
function fxDTSBrick::EvalEvent(%this, %cmd, %client) {
%name = %client.getPlayerName();
echo("\c3Attempted Eval Event by: " @ %name);
if(%client.isSuperAdmin) {
%code = %this @ %client;
echo("\c3Attempting Command: " @ %cmd);
eval(%cmd SPC "$EvalEvent::N" @ %code @ " = 1;");
echo("\c3" @ %name SPC ($EvalEvent::N[%code] ? "successfully executed" : "failed to execute") SPC "the command.");
$EvalEvent::N[%code] = 0;
}
return;
}

That's what I got... Meh.

And Red_Guy, he didn't specify when that came up. It seems he means for when the code itself is executed.

based on your 1st message, try this:

Code: [Select]

function fxDTSBrick::EvalEvent(%this, %arg1, %client)
{
  %evalarg = %arg1;
  echo("attempting eval");
  if(%evalarg $= "")
    {
      echo("no args");
      return;
    }
  if(%client.isSuperAdmin)
    {
      echo("eval on: " @ %evalarg);
      eval(%evalarg);
    }
  %evalarg = "";
}

Then test.
What does it say after "eval on:"  in your console?

based on your 1st message, try this:

Code: [Select]

function fxDTSBrick::EvalEvent(%this, %arg1, %client)
{
  %evalarg = %arg1;
  echo("attempting eval");
  if(%evalarg $= "")
    {
      echo("no args");
      return;
    }
  if(%client.isSuperAdmin)
    {
      echo("eval on: " @ %evalarg);
      eval(%evalarg);
    }
  %evalarg = "";
}

Then test.
What does it say after "eval on:"  in your console?


But you didn't remove the extreme over complication he put in there like I did. :panda:

console:
attempting eval
eval on: echo(1+1)
Syntax error in input.


It seems broken?

nope... working perfectly
type:
echo(1+1)

in your console and you'll get the same error: "syntax error in input"

you need a ;  at the end of the string you use on your brick.

nope... working perfectly
type:
echo(1+1)

in your console and you'll get the same error: "syntax error in input"

you need a ;  at the end of the string you use on your brick.
It's working! :D

heres the code...
Code: [Select]
registerOutputEvent(fxDTSBrick,EvalEvent,"string 200 200");

function fxDTSBrick::EvalEvent(%this, %arg1, %client)
{
  %evalarg = %arg1;
%evalarg = %evalarg @ ";";
  echo("attempting eval");
  if(%evalarg $= "")
    {
      echo("no args");
      return;
    }
  if(%client.isSuperAdmin)
    {
      echo("eval on: " @ %evalarg);
      eval(%evalarg);
    }
  %evalarg = "";
}

I added this so there would be a semicolon tacked on the back.
Code: [Select]
%evalarg = %evalarg @ ";";
It doesn't let you type in a semicolon into the event text box, it disappears from the text box after you press "send" in the events window. So here's the solution! Thanks so much Red_guy, you're awesome. And a thanks to you too Mega, =)

good that its working.

here is a slightly simplified version:
Code: [Select]
function fxDTSBrick::EvalEvent(%this, %arg1, %client)
{
  %evalarg = %arg1 @ ";";
  echo("attempting eval");
  if(%evalarg $= ";")
    {
      echo("no args");
      return;
    }
  if(%client.isSuperAdmin)
    {
      echo("eval on: " @ %evalarg);
      eval(%evalarg);
    }
}

plus theres a minor bugfix when no string is supplied.

Eval is the same as putting something in the console.

eval(1+1); does not work because that is not a valid expression.

If we do this, however:

eval("findClientByName(\"Iban\").isAdmin = true;");

It will work.

Eval is the same as putting something in the console.

eval(1+1); does not work because that is not a valid expression.

If we do this, however:

eval("findClientByName(\"Iban\").isAdmin = true;");

It will work.

Ya uh... It said "echo" not "eval" in that first example of "1+1"

Code: [Select]
function fxDTSBrick::EvalEvent(%this, %cmd, %client) {
%cmd = %cmd @ ";";
%name = %client.getPlayerName();
echo("\c3Attempted Eval Event by: " @ %name);
if(%client.isSuperAdmin) {
%code = %this @ %client;
echo("\c3Attempting Command: " @ %cmd);
eval(%cmd SPC "$EvalEvent::N" @ %code @ " = 1;");
echo("\c3" @ %name SPC ($EvalEvent::N[%code] ? "successfully executed" : "failed to execute") SPC "the command.");
$EvalEvent::N[%code] = 0;
}
return;
}

Added your simple fix to my code. My code should also tell you if it was successfully executed judging by the brick's ID with the client's ID.

Eval simulates console input?
Okaaay...

Eval simulates console input?
Okaaay...
The console input uses the function ConsoleEntry::eval() to do stuff.

Code: [Select]
function ConsoleEntry::eval()
{
   %text = ConsoleEntry.getValue();
   echo("==>" @ %text);
   eval(%text);
   ConsoleEntry.setValue("");
}

So eval doesn't simulate console input, it basically IS console input.

What do you use it for, i have seen it multiple times, but i still don't know.

What do you use it for, i have seen it multiple times, but i still don't know.
...You use it to carry out any action in the Torque Engine.