Variables in $effect[]

I'm working on a very simple script for the Generic Summer Holiday and I was wondering if it's possible to put a variable skill name in the follow code:

Code:
string summer_effect = "Full-Body Tan";
if(have_effect($effect[summer_effect]) > 0)
...

I keep getting an error and I've resorted to not using the variable. But I thought if I could get it to work, it'd be easier for me to share the script with others (read: less lines for them to customize for their own use)
 

jasonharper

Developer
The whole point of $type[...] is that it produces a constant. To convert a varying string to an effect, you'd use the to_effect() function. Or better yet, have the variable be the effect rather than its name:
Code:
effect summer_effect = $effect[Full Body Tan];
if (have_effect(summer_effect) > 0) ...
 
@Sputnik: That does work. The way I understood it Ice wanted the string summer_effect to be a user-configurable preference at the beginning of his script. He wanted the script to be able to recognize it as an effect however, hence the use of to_effect().
 
Last edited:
FN Ninja is right on what I was looking for.

@jasonharper, that would work, but I'm also using that variable of the effect name to print some statements to the CLI, so I'll stick with to_effect(). Thanks for that suggestion though. I could use that in the future.
 

heeheehee

Developer
Staff member
Alternatively, you could declare it as an effect, and convert it to a string when you want to output something to the CLI. So...
Code:
effect summer_effect = $effect[Full-Body Tan];
if(have_effect(summer_effect) > 0) {
	print("You have "+have_effect(summer_effect)+" turns of "+to_string(summer_effect));
}
 

zarqon

Well-known member
You can print effects (and other mafia types). They are automatically typecast to strings. It's usually desirable to have variables be the type that they represent.

PHP:
effect foo = $effect[full-body tan];
print(foo);   // prints "Full-Body Tan"
 
Top