Tutorial Help

DaMaster0

Member
Tutorial Help - still have questions

Can anyone recommend a tutorial for KOL mafia? I'm new, and I just finished the tutorials on the kol mafia page, but I really need to do a few more exercises before I get comfortable with all the commands. I did a few google searches but couldn't find any. Is there any more out there??? :confused:
 
Last edited:

Bale

Minion
If you read the tutorial, then there's just the wiki: http://wiki.kolmafia.us/index.php?title=Main_Page

Most though that's just a reference to help you find the command you want so I'd say you're ready to get comfortable by dissecting someone else's scripts and making one of your own. Welcome to our community, we'll be glad to help you out once you've got problems that you can show us.
 

Camber

Member
And be sure to download and look at all the wonderful scripts on this site for examples. There are big complex scripts as well as simple ones to get started with. And have fun!
 

mredge73

Member
Once you have an Idea on what you want to create, I would recommend you download a bunch of scripts that are similar to it and try to dissect them like Bale said above. Zarqon's Zlib and my function support script contain lots of starter functions that can be called from another script. These toolbox type scripts can be helpful since they contain functions that are used often by many different types of scripts.

Here are a few tools that I found helpful:
Mafia's Internal Database, Help->Internal Database
Type ashref in the Cli and copy that to a reference file
Type help in the cli and copy that to a reference file
Download mafia's source and take a look at the data folder, lots of useful info is in there.
Notepad ++ combined with Bale's custom language is very helpful in writing scripts
If you ever get into using matching this site is great:http://www.fileformat.info/tool/regex.htm
 

Bale

Minion
Type ashref in the Cli and copy that to a reference file
Type help in the cli and copy that to a reference file
Cannot recommend this enough. mafia is it's own best resource. You can also give a parameter to ashref or help to narrow the search.

Notepad ++ combined with Bale's custom language is very helpful in writing scripts
I love Notepad++ and it is free! You can find my cutom language file here. Just unzip it and drop it into your notepad++ program directory.

If you ever get into using matching this site is great:http://www.fileformat.info/tool/regex.htm
That's an advanced lesson, but a useful one. Other useful references for regular expressions are this tutorial and this function list. This is a very powerful tool! You can use it to make all sorts of difficult tasks fairly simple. It is however, a bit tricky to learn.
 
Last edited:

DaMaster0

Member
Thanks guys. You were really helpful. I'll start looking at different scripts on the forums to dissect. But I have 2 more questions. 1: When you write a function that requires arguments, can you specify these arguments in the CLI? 2: I want to download information. Is that possible? When I say download information, I mean can I go to the mall, find out the price of an item, and ask the user if it's OK to purchase it.
 
Last edited:

mredge73

Member
1: The only way that I know how to do this is with the main() function. in the main you can specify arguments and when called the user has to enter values for those arguments.

For example save this to a .ash file and run it to see how it works:
Code:
main (int Enter_a_Digit)
{
print("You entered " +Enter_a_Digit+ " on the startup of this script!");
}

2: end user interaction is limited mostly to boolean user_confirm() commands. These are just pop-up boxes that give the user a yes or no choice and thats it.

For example run this:
Code:
main (int Enter_a_Digit)
{
if (user_confirm("Do you want to see what you entered"))
print("You entered " +Enter_a_Digit+ " on the startup of this script!");
}
 

DaMaster0

Member
I have another question. I have this code:

Code:
int mall (item item1)
{
	int price;
	if ( item_amount( $item[item1] ) <  1 )
	{
		price = mall_price($item[item1]);
		return price;
	}
	print("You either have the following item, or it is not available in the mall: " + item1);
	return 0;
}

and this to call it:

Code:
currentprice = mall($item[tiny  plastic disco bandit]);

when I run the scipt I get this:

>test.ash

Searching for "item #13"...
You do not have enough meat to purchase these items. You need 700000000 meat.
Requests complete.

I went to the actuall mall and searched for item #13 and it is an item, and it costs 700000000 meat, but why is my program searching for that??
 

jasonharper

Developer
$item[...] (and in general, all forms of $type[...]) is how you write a constant in ASH. $item[item1] refers to the item named "item1" (which is an unambiguous match for "item #13"); it does not in any way refer to your parameter named item1. To use a parameter or variable, just write its name, you've already told ASH what type it is when you declared it.
 

DaMaster0

Member
$item[...] (and in general, all forms of $type[...]) is how you write a constant in ASH. $item[item1] refers to the item named "item1" (which is an unambiguous match for "item #13"); it does not in any way refer to your parameter named item1. To use a parameter or variable, just write its name, you've already told ASH what type it is when you declared it.

That just blew right past me. Something about it searching for item1 and that's a match to item #13? How do I make it search for what I call in the arguments?
 

matt.chugg

Moderator
item someitem = $item[tinyplastic disco bandit] is how to declare a variable of type item and assign an item to it

now someitem == $item[tinyplastic disco bandit] so you can just refer to it as someitem NOT $item[someitem]

the fix to your code would be

Code:
int mall (item item1)
{
	int price;
	if ( item_amount(item1) <  1 )
	{
		price = mall_price(item1);
		return price;
	}
	print("You either have the following item, or it is not available in the mall: " + item1);
	return 0;
}

because item1 as a string didn't have an exact match with an item it was using cleverness to get the best match which happened to be #item13

see the wiki page here, for datatype contants

http://wiki.kolmafia.us/index.php?title=Datatype_Constants
 
Last edited:

Camber

Member
Ok, let me attempt to clarify from a non-developer standpoint. In the declaration of the function mall, you defined item1 as type item; therefore, since it is defined as such, you just need to use item1 instead of '$item[item1]' as shown below. You also forgot to type currentprice in main().

To help you see what Jason was talking about, go into mafia's internal database (under help) and in the items tab, type in 'item1' - it brings up item #603 named "Item #13".

Code:
int mall (item item1)
{
	int price;
	if ( item_amount( item1 ) <  1 )
	{
		price = mall_price( item1 );
		return price;
	}
	print("You either have the following item, or it is not available in the mall: " + item1);
	return 0;
}

void main() {
	int currentprice = mall($item[tiny plastic disco bandit]);
	print ("Current Price of " + $item[tiny plastic disco bandit] + " is: " + currentprice) ;
}

* D'oh! Ninja'd ! Good explaination.
 

DaMaster0

Member
ok, thank you. Now my script works, but I want to know if there is a way for it to request an int from the user.
 

Camber

Member
See MrEdge73's post above - he explains it all there.

To help explain...
main (int Enter_a_Digit)

if a main requires a variable, in this case Enter_a_Digit, a box pops up asking for input.
 

Veracity

Developer
Staff member
That kind of attitude/language encourages the developers to listen to you, don't you think? I know that I really enjoy seeing the word "dumb" applied to my work.
 

Bale

Minion
While I also think it would be helpful if there was a way to prompt the user for a variable other than boolean, I never thought to insult the intellect of the nice people who work on this program in their spare time for ZERO money, just because they love the game and they love the people who use mafia. Well, at least they like most of the people who use mafia. There's an obvious exclusion in that they may not like you anymore.

Moral: The developers don't add always features that they don't personally use unless you ask nicely, simply because it takes time away from the job that pays their bills and whatever else they fill their lives with.
 

Grotfang

Developer
Can you explain the situation you need that functionality for? In my experience, for the vast majority of scripts, good preparation means most arguments, if not all, can either be hard coded, or used as arguments in main(), as has previously been shown.

In fact, I can't think of any situation where I have thought to myself;

"Hey, not having this capacity to prompt the user for variables part way through this script means I cannot achieve this goal!".

It may be a useful feature, but I really don't think it is an essential one, and the absence of it doesn't hugely surprise me. In addition, if you really think it is a simple fix, then why don't you add it yourself? The source code is publicly available, after all.
 

Catch-22

Active member
While I also think it would be helpful if there was a way to prompt the user for a variable other than boolean, I never thought to insult the intellect of the nice people who work on this program in their spare time for ZERO money, just because they love the game and they love the people who use mafia. Well, at least they like most of the people who use mafia. There's an obvious exclusion in that they may not like you anymore..

Yeah, I don't think he was calling anyone dumb specifically, just mentioning that it was dumb that you couldn't do it.

Anywho... I guess you could edit the RuntimeLibrary.java and recompile from SVN, you'd probably need to add something like this to params:

Code:
params = new Type[] { DataTypes.STRING_TYPE };
functions.add( new LibraryFunction( "get_int", DataTypes.INT_TYPE, params ) );

and here's the function:

Code:
public static Value get_int( final Value message )
{
	try
	{
		return DataTypes.parseIntValue( InputFieldUtilities.input( message.toString() ) );
	}
	catch ( NumberFormatException e )
	{
		throw LibraryFunction.interpreter.runtimeException( "Cannot convert \"" + string + "\" to an integer." );
	}
}

Ugh.. Looks terrible without source formatting and proper indentation.
Edit: Thanks lostcalpolydude, hehe.

I dunno how well it will work, if at all, I don't really have time to compile and test, it's 3AM and I have work in 4 hours :(
 
Last edited:
Top