Foreach in custom expression?

   2861   3   1
User Avatar
Member
7024 posts
Joined: July 2005
Offline
How the heck do you use foreach in a custom expression?? Please, oh God, please someone document custom expressions!!

string allgroups = primgrouplist(“.”);

foreach i allgroups
{
xxx do something with group xxx
}

Please help…

Cheers,

Peter B
User Avatar
Member
7708 posts
Joined: July 2005
Online
This seems to work …


{
string str = “a b c d”;
string token = “”;

for ( i = 0 ; i < argc(str); i++ )
{
token = arg(str, i);
run(“message `token`”);
}
}
User Avatar
Member
941 posts
Joined: July 2005
Offline
edward
This seems to work …
Yes. Short answer is there *isn't* a foreach command for custom expressions. I believe the only functions available within a custom expression are functions from the expression language (i.e: the stuff you get from “exhelp”). So for loop control you have for and while and… that's about it.

Here's another trivial example I just tried and it also works (useless since you can get this functionality from arg() and argc(), but just to see if it worked):


# Returns the group name given an (numerical) index
#————————————————————-
string grindex(string op, float ndx) {
string ret = “”;
if(ndx>=0) {
string gl = primgrouplist(op);
if(ndx<argc(gl)) ret=arg(gl,ndx);
}
return ret;
}

Which you can test in the textport with something like:
echo `grindex(“/obj/geo1/__display_sop__”,0)`

Cheers!
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
7024 posts
Joined: July 2005
Offline
Thanks guys.

Cheers,

Peter B
  • Quick Links