Game Development Community

How to execute a variable??

by AIDan · in Torque Game Engine · 12/17/2001 (5:01 am) · 2 replies

%command= "echo("done.");

How can I run this command??

greetings
Daniel

#1
12/17/2001 (7:11 am)
You would do:
%command = "echo(\"done.\");";

eval(%command);

This is also helpful if you need to set a global variable that would normally give you a syntax error.

// this would normally give you a syntax error:
$GlobalVar::[%whatever] = %whatever2;

// this is an alternative:
eval("$GlobalVar::" @ %whatever @ " = " @ %whatever2 @ ";");

If you put a bracket next to the double colons like that it gives you an error. But you could do:

%int = 325;
$GlobalVar::Whatever[%int] = %whatever;

// to get the string:
%test = $GlobalVar::Whatever325;
// or
%test = $GlobalVar::Whatever[325];

// it doesn't have to be a number either, it can be a string:
%str = "Hello";
$GlobalVar::Whatever[%str] = %whatever;

// to get the string:
%test = $GlobalVar::WhateverHello;
// or
%test = $GlobalVar::Whatever["Hello"];

Torque's scripting language is very versitile, it can do almost anything.


Dark
#2
12/17/2001 (7:50 am)
Very nice and useful indeed.