Using c++ like macrodefinitions

I want to replace read(“name”); string by

var name;
name=gameObject.Find("name");
if(!name)
    return;
name=name.param;

before the build and replace back after it, because if a script needs 20 external variables copypasting it and replacing names becomes awful.

How can I do it? I thought about makefile. Can I specify it for my project?
Another solution I considered was to create scripts dynamically. Is it possible?

__

I know about editor options to specify a public var as an argument, but it doesn’t work with standard types and seems rather messy.

I don’t normally like to tell people ‘youre doing it wrong’, but in this case, if you are finding yourself having to resort to wanting c++ macros or auto script editing, I suspect you’ve maybe just gone down the wrong path a bit.

Could you past up an example of the script in it’s ‘awful’ form so we can see exactly what it looks like, and maybe we can come up with a better way of writing it.

fyi - if my initial feeling of what you’re trying to do is correct, I would be tempted to store a list of component names in an array. Then just iterate over each component name and execute your code on it. I don’t know the exact java script to do it (I do c#), but in psuedo code:

component_names = ["hello","thing","foo"]

foreach name in component_names
   component = gameObject.Find(name)
   if(!component)
       return;
   component = component.param

Presumably there’s some stuff after that or your code wouldn’t actually do anything, but you get the point. Store a list of the names you’re interested in, then execute your common code on each one.

-Chris

public static function read(name:String,target):String
{
target.self=target;
return “var rtmp=self.gameObject.GetComponent("”+name+“");”+“if(!rtmp)return; self.”+name+“=rtmp.param;”;
}

eval(read("name",this));

It may cause performance issues, I’m yet not sure about it. Besides, a caller needs to have self variable, and all “name” variables declared.