Game Development Community

Fun with eval

by Dumbledore · in Torque Game Engine · 08/14/2008 (2:40 pm) · 3 replies

Does this have any merit at all?

// global
$VehicleType::MotorCycle::Cost = 50; 

function getCost(%vehicleType)
{
      eval("%cost = $VehicleType:: @ %vehicleType @ ::Cost");
      return %cost;  
}

function main()
{
     echo( getCost("MotorCycle");
}

I get a parse error, but I thought you could do something like this.

#1
08/14/2008 (2:48 pm)
Do you ever define $VehicleType? I don't see it in your code anywhere. Also, shouldn't it be
eval("%cost = " @ $VehicleType @ "::" @ %vehicleType @ "::Cost");
#2
08/14/2008 (3:02 pm)
Add a semicolon to the end of your eval, Torque doesn't assume it.
#3
08/14/2008 (4:54 pm)
Thanks! you gyys are terrific.