Author Topic: Creating a datablock using a variable name  (Read 826 times)

Neither of these work. They both cause syntax errors when the game is starting up.
Code: [Select]
eval("datablock ShapeBaseImageData("@%hatNameNoSpace@")
{
shapeFile = $CobS::HatsFP@%fileName;
emap = true;
mountPoint = $HeadSlot;
offset = \"0 0 0\";
eyeOffset = \"0 0 0.4\";
rotation = eulerToMatrix(\"0 0 0\");
scale = \"1 1 1\";
doColorShift = false;
colorShiftColor = \"1.000 1.000 1.000 1.000\";
};");
Code: [Select]
datablock ShapeBaseImageData(%hatNameNoSpace)
{
shapeFile = $CobS::HatsFP@%fileName;
emap = true;
mountPoint = $HeadSlot;
offset = "0 0 0";
eyeOffset = "0 0 0.4";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = false;
colorShiftColor = "1.000 1.000 1.000 1.000";
};

This on is unreadable but works :/
Code: [Select]
eval("datablock ShapeBaseImageData("@%hatNameNoSpace@"){ shapeFile = $CobS::HatsFP@%fileName; emap = true; mountPoint = $HeadSlot; offset = \"0 0 0\"; eyeOffset = \"0 0 0.4\"; rotation = eulerToMatrix(\"0 0 0\"); scale = \"1 1 1\"; doColorShift = false; colorShiftColor = \"1.000 1.000 1.000 1.000\"; };");
Is there one that's readable AND works? :D

if you don't use eval and actually write it in a .cs file and save it in a folder in Add-Ons it will work as the readable version.

Dont use eval
Code: [Select]
datablock ShapeBaseImage(DummyHatName)
{
           shapeName = $CobS::HatsFP@%filename;
           emap = true;
           mountPoint = $HeadSlot;
           offset = "0 0 0";
           eyeOffset = "0 0 0.4";
           rotation = eulerToMatrix("0 0 0");
           scale = "1 1 1";
           doColorshift = false;
           colorShiftColor = "1 1 1 1";
};
DummyHatName.setName(%hatNameNoSpace);

:)

The second code snippet doesnt use eval and gave me a syntax error

Is %filename ever defined in the script?

Just reread what brian said. I didnt see that last line there. Thanks, that worked!
« Last Edit: January 01, 2012, 05:44:03 PM by DYLANzzz »

The reason your first eval attempt didn't work is because you can't break strings across multiple lines.

Code: (No!) [Select]
echo("This is
a test.");
Code: (Yes!) [Select]
echo("This is"
@"a test.");
Code: (Yes!) [Select]
echo("This is"@
"a test.");
Code: (No!) [Select]
echo("This is"@
@a test.");