Difference between revisions of "To effect"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
(Created page with '{{ #vardefine:name|to_effect}}{{ #vardefine:return_type|effect}}{{ FunctionPage| name={{#var:name}}| function_category=Datatype Conversions| function1={{Function| name={{#var:n…')
 
imported>Eliteofdelete
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Datatype Conversions|
 
  
 
function1={{Function|
 
function1={{Function|
Line 29: Line 28:
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
 
parameter1={{Param|skill|convert}}|
 
parameter1={{Param|skill|convert}}|
p1desc={{Pspan|convert}} is the int, string or skillt to convert|
+
p1desc={{Pspan|convert}} is the int, string or skill to convert|
 
}}|
 
}}|
function_description=When supplied an int or string, returns the effect that corresponds to the specified parameter {{pspan|convert}}. When supplied a skill, this returns the effect that is given when the skill {{pspan|convert}} is cast on a player.|
+
function_description=When supplied an int or string, returns the effect that corresponds to the specified parameter {{pspan|convert}}. When supplied a skill, this returns the effect that is given when the skill {{pspan|convert}} is cast on a player.<br>Note: This function can not return effects of items. For that, use [https://wiki.kolmafia.us/index.php?title=Effect_modifier effect_modifer()]. If you are attempting to see the duration of an effect, use [https://wiki.kolmafia.us/index.php?title=Numeric_modifier numeric_modifier(item, "effect duration")].|
  
needscode=yes|
+
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following example shows basic to_effect operations.||
 +
code=
 +
<syntaxhighlight>
 +
//int
 +
print(to_effect(100), "green");
 +
//strings
 +
print(to_effect("Smooth"), "green");
 +
print(to_effect("Smooth Move"), "green");
 +
//skills
 +
print(to_effect($skill[Disco Aerobics]), "green");
 +
 
 +
</syntaxhighlight>|
 +
moreinfo=For more info about effects from numbers and skills, see [http://kol.coldfront.net/thekolwiki/index.php/Effects Effects].
 +
<br>It gives the following output.
 +
<pre>
 +
Stabilizing Oiliness
 +
Hella Smooth
 +
Smooth Movements
 +
Disco State of Mind
 +
</pre>
 +
}}
 +
 
 +
{{CodeSample|
 +
description=<br>Following example tells which buffs you are missing but could have.||
 +
code=
 +
<syntaxhighlight>
 +
void buffs_check() {
 +
int amount;
 +
boolean have_buff;
 +
boolean[skill] active_buffs, bot_buffs, castable_buffs;
 +
  foreach it in $skills[] {
 +
      amount = have_effect(to_effect(it));
 +
      if (amount == 0)
 +
        have_buff = false;
 +
      else have_buff = true;
 +
     
 +
      if (have_buff) //Currently have the effect active
 +
        active_buffs[it]=have_buff;
 +
      if (it.buff == true && !have_buff && it.class != $class[none] && it.level != -1 && it.dailylimit == -1 && it != $skill[Spiky Shell] && it != $skill[Antibiotic Saucesphere]) //buff bot buffs
 +
        bot_buffs[it]=have_buff;
 +
      if (have_skill(it) && it.combat != true && !have_buff && to_effect(it) != $effect[none]) //buffs you can cast on yourself
 +
        castable_buffs[it]=have_buff;
 +
  }
 +
  print("You currently have the following buffs active:", "red");
 +
  foreach it in active_buffs
 +
      print(""+it+"", "green"); 
 +
  print("");
 +
  print("You could get the following buffs from a buff bot:", "red");
 +
  foreach it in bot_buffs
 +
      print(""+it+"", "blue"); 
 +
  print("");
 +
  print("You could cast the following buffs on yourself:", "red");
 +
  foreach it in castable_buffs
 +
      print(""+it+"", "purple");
 +
}
 +
buffs_check();
 +
</syntaxhighlight>|
 +
 
 +
}}|
  
 
special=If {{pspan|convert}} is an effect that cannot be given by use of a skill, and is supplied as such, or no match is found for a supplied string or int type, this function returns $effect[ none ].|
 
special=If {{pspan|convert}} is an effect that cannot be given by use of a skill, and is supplied as such, or no match is found for a supplied string or int type, this function returns $effect[ none ].|
 
}}
 
}}
 +
 +
[[Category:Datatype Conversions]]

Latest revision as of 00:35, 22 September 2019

Function Syntax

effect to_effect(int convert )

effect to_effect(string convert )

effect to_effect(skill convert )

  • convert is the int, string or skill to convert

When supplied an int or string, returns the effect that corresponds to the specified parameter convert. When supplied a skill, this returns the effect that is given when the skill convert is cast on a player.
Note: This function can not return effects of items. For that, use effect_modifer(). If you are attempting to see the duration of an effect, use numeric_modifier(item, "effect duration").

Code Samples

Following example shows basic to_effect operations.

//int
print(to_effect(100), "green");
//strings
print(to_effect("Smooth"), "green");
print(to_effect("Smooth Move"), "green");
//skills
print(to_effect($skill[Disco Aerobics]), "green");

For more info about effects from numbers and skills, see Effects.


It gives the following output.

Stabilizing Oiliness
Hella Smooth
Smooth Movements
Disco State of Mind



Following example tells which buffs you are missing but could have.

void buffs_check() {
int amount;
boolean have_buff;
boolean[skill] active_buffs, bot_buffs, castable_buffs;
   foreach it in $skills[] {
      amount = have_effect(to_effect(it));
      if (amount == 0)
         have_buff = false;
      else have_buff = true;
      
      if (have_buff) //Currently have the effect active
         active_buffs[it]=have_buff;
      if (it.buff == true && !have_buff && it.class != $class[none] && it.level != -1 && it.dailylimit == -1 && it != $skill[Spiky Shell] && it != $skill[Antibiotic Saucesphere]) //buff bot buffs
         bot_buffs[it]=have_buff;
      if (have_skill(it) && it.combat != true && !have_buff && to_effect(it) != $effect[none]) //buffs you can cast on yourself
         castable_buffs[it]=have_buff;
   }
   print("You currently have the following buffs active:", "red");
   foreach it in active_buffs
      print(""+it+"", "green");   
   print("");
   print("You could get the following buffs from a buff bot:", "red");
   foreach it in bot_buffs
      print(""+it+"", "blue");   
   print("");
   print("You could cast the following buffs on yourself:", "red");
   foreach it in castable_buffs
      print(""+it+"", "purple");
}
buffs_check();

Special

If convert is an effect that cannot be given by use of a skill, and is supplied as such, or no match is found for a supplied string or int type, this function returns $effect[ none ].