Difference between pages "Talk:ASH Errors" and "Equip"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
imported>PhilmASTErpLus
(Thanks for input, but does anyone know whether there exists other forms of code that can cause this error?)
 
(add new overloads for equipping familiars directly and code example)
 
Line 1: Line 1:
Is this like were things like <font color="#ff7000">Script parsing error (X.ash, line Y)</font> are listed?--[[User:Icon315|Icon315]] 22:33, 14 April 2010 (UTC)
+
{{
 +
#vardefine:name|equip}}{{
 +
#vardefine:return_type|boolean}}{{
  
:It's where they WILL be listed, once they are listed. --[[User:Bale|Bale]] 22:52, 14 April 2010 (UTC)
+
FunctionPage|
 +
name={{#var:name}}|
  
What Bale said. Also, I changed that to orange; I kept trying to click on it. :( --[[User:StDoodle|StDoodle (#1059825)]] 00:35, 15 April 2010 (UTC)
+
function1={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
}}|
  
Also, if anyone's feeling particularly ambitious, https://kolmafia.svn.sourceforge.net/svnroot/kolmafia/src/net/sourceforge/kolmafia/textui/Parser.java should help. Just look for all the instances of parseException. (Speaking of which, would it be useful if these were presented in the order that they're checked?) --[[User:Heeheehee|Heeheehee]] 00:17, 17 April 2010 (UTC)
+
function2={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
parameter2={{Param|slot|where}}|
  
I think alphabetical order would be better: this page is going to be excellent for first-time ASH scripters to understand what's wrong with their script. --[[User:Slyz|Slyz]] 10:41, 17 April 2010 (UTC)
+
}}|
  
Should we add the correct examples? Or are the fixes clear enough?
+
function3={{Function|
--[[User:Slyz|Slyz]] 08:36, 18 April 2010 (UTC)
+
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|slot|where}}|
 +
parameter2={{Param|item|equip_me}}|
 +
p1desc={{Pspan|equip_me}} is the item to equip|
 +
p2desc={{Pspan|where}} is the slot to place the item in|
 +
}}|
  
If anything particularly complicated shows, we can give both. But so far, if you can't follow as written, I'm not sure you ever will. (That's the hypothetical "you," not the specific "hey Slyz what's wrong with you, you"). --[[User:StDoodle|StDoodle (#1059825)]] 23:35, 19 April 2010 (UTC)
+
function4={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
parameter2={{Param|familiar|fam}}|
  
 +
}}|
  
 +
function5={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|familiar|fam}}|
 +
parameter2={{Param|item|equip_me}}|
 +
p1desc={{Pspan|equip_me}} is the item to equip|
 +
p2desc={{Pspan|where}} is the familiar to equip the item on|
 +
}}|
  
{{CodeSample|description=The following code results in an error.
+
function_description=Attempts to equip the item {{pspan|equip_me}} in the slot {{pspan|where}} if specified, and returns true if the operation was successful, and false if it was not. If parameter {{pspan|where}} is not specified, it defaults to the "standard" place for such an item (main-hand for 1-handed weapons, first open slot for accessories or acc1 if no slots are open).
|code=<syntaxhighlight>
+
*If {{pspan|where}} is specified and {{pspan|equip_me}} is set to $item[none], this function will unequip whatever is in slot {{pspan|where}} and return true.  
void my_function( string myvar = "value" )
+
*If {{pspan|where}} is not specified and {{pspan|equip_me}} is set to $item[none], the function aborts and you get a funky error because that makes no sense.  
{
+
*If you cannot equip {{pspan|equip_me}}, or {{pspan|where}} is supplied and the item cannot be used in that slot, you will be given an error message and this function will return false.
  /* Do something */
+
*The overload for equipping a familiar with {{pspan|equip_me}} can be used to equip familiars with familiar equipment without requiring the familiar to be your currently active familiar. This will return false if you don't have (or can't use) the familiar or if the familiar can't equip the item you are attempting to equip.
}
+
&nbsp;|
</syntaxhighlight>}}
 
Error message: <blockquote>Cannot initialize parameter myvar (filename.ash, line X)</blockquote>
 
I'd like to add this to the article myself, but I'm not sure how to explain its exact nature. Would this message appear only in a situation like the above code? --[[User:PhilmASTErpLus|PhilmASTErpLus]] 09:30, 28 July 2010 (UTC)
 
: Looks like a conflict of functionality -- the two ways to initialize a variable are '''string myvar''' and '''string myvar = "value"'''. The only proper way to define a parameter is the former. So basically you're defining a parameter, which then gets initialized with a value. This would lead to all sorts of problems, so the parser catches this exception and throws an error. I'm not really sure why anyone would want to do this, but I guess you can add it? (fun fact: the value that you set the parameter to doesn't actually have to match the datatype for this error to appear) --[[User:Heeheehee|Heeheehee]] 16:47, 28 July 2010 (UTC)
 
  
I'm guessing he tried it for the same reason I did; in some languages, that's how you provide a default value for a parameter. It's usually functionally equivalent to having two different versions of my_function() defined, one which accepts a single string, and one which accepts no parameters, and calls the other with the default value. Usually it isn't a big deal to do things one way or the other, but the method given above can actually be much simpler if you get into a large number of overloaded versions of a single function. --[[User:StDoodle|StDoodle (#1059825)]] 18:30, 28 July 2010 (UTC)
+
code1={{CodeSample|
: In that case, would this be a reasonable low-priority feature request? --[[User:Heeheehee|Heeheehee]] 18:44, 28 July 2010 (UTC)
+
title=Code Sample|
 +
description=Equips the Swashbuckling Getup carefully to ensure that the parrot is in the second accessory slot.|
 +
code=
 +
<syntaxhighlight>
 +
equip($item[eyepatch]);
 +
equip($item[swashbuckling pants]);
 +
equip($slot[acc2], $item[stuffed shoulder parrot]);
 +
</syntaxhighlight>
 +
}}|
  
That's up to the devs, but I have a feeling it would be a non-trivial change to get a trivial benefit, and therefore ignored. Unless someone has a good argument for a situation in which it would make a huge difference. --[[User:StDoodle|StDoodle (#1059825)]] 21:08, 28 July 2010 (UTC)
+
code2={{CodeSample|
 +
title=Code Sample|
 +
description=Equips the blue plate on the Shorter-Order Cook without switching to it first.|
 +
code=
 +
<syntaxhighlight>
 +
equip($familiar[shorter-order cook], $item[blue plate]);
 +
</syntaxhighlight>
 +
}}|
  
 +
see_also={{SeeAlso|can_equip|equipped_amount|equipped_item|have_equipped}}|
 +
cli_equiv=The CLI commands "equip" (and others, for specific slots) function similarly.|
 +
}}
  
{{CodeSample|description=Hardly worth suggesting. The KoLmafia method works just fine:
+
[[Category:Equipment]]
|code=<syntaxhighlight>
 
void my_function()
 
{
 
  my_function("value");
 
}
 
</syntaxhighlight>}}
 
--[[User:Bale|Bale]] 04:31, 29 July 2010 (UTC)
 
:Yeah, when I posted that code, I wasn't thinking about requesting for a default parameter feature. All I'd like to know is whether there is a general case that will trigger this particular error message; for example, I would have expected this instead of "expected ) but got =" message when I tried assignment in the conditional for the <code>if</code> and <code>while</code> statements. --[[User:PhilmASTErpLus|PhilmASTErpLus]] 13:17, 29 July 2010 (UTC)
 

Latest revision as of 16:49, 12 April 2024

Function Syntax

boolean equip(item equip_me )

boolean equip(item equip_me ,slot where )

boolean equip(slot where ,item equip_me )

  • equip_me is the item to equip
  • where is the slot to place the item in

boolean equip(item equip_me ,familiar fam )

boolean equip(familiar fam ,item equip_me )

  • equip_me is the item to equip
  • where is the familiar to equip the item on

Attempts to equip the item equip_me in the slot where if specified, and returns true if the operation was successful, and false if it was not. If parameter where is not specified, it defaults to the "standard" place for such an item (main-hand for 1-handed weapons, first open slot for accessories or acc1 if no slots are open).

  • If where is specified and equip_me is set to $item[none], this function will unequip whatever is in slot where and return true.
  • If where is not specified and equip_me is set to $item[none], the function aborts and you get a funky error because that makes no sense.
  • If you cannot equip equip_me, or where is supplied and the item cannot be used in that slot, you will be given an error message and this function will return false.
  • The overload for equipping a familiar with equip_me can be used to equip familiars with familiar equipment without requiring the familiar to be your currently active familiar. This will return false if you don't have (or can't use) the familiar or if the familiar can't equip the item you are attempting to equip.

 

Code Sample

Equips the Swashbuckling Getup carefully to ensure that the parrot is in the second accessory slot.

equip($item[eyepatch]);
equip($item[swashbuckling pants]);
equip($slot[acc2], $item[stuffed shoulder parrot]);

Code Sample

Equips the blue plate on the Shorter-Order Cook without switching to it first.

equip($familiar[shorter-order cook], $item[blue plate]);

CLI Equivalent

The CLI commands "equip" (and others, for specific slots) function similarly.

See Also

can_equip() | equipped_amount() | equipped_item() | have_equipped()