Mafia versioning & scripts

Catch-22

Active member
The problem with a version() function is that sometimes it would return a release number and other times it would return a revision number. It's rather troublesome, but I suppose that decoding the meaning of the output could be left to teh script writer.

Easier to "decode" than you might think ;)

Revision responses always contain an r before the number, major versions always have a v, so you can determine what kind of build it is that way pretty easily.

ie. "KoLmafia r7643" or "KoLmafia v13.5"

You don't even have to do that though, because major versions are most likely going to always have lower numbers than a revision build.

A really simple version check could be done with:
Code:
if (to_int(version()) < 135) {
            abort("Please update to version 13.5");
        } else if (to_int(version()) < 7643) {
            abort("Please update to revision 7543);
        }
 

Bale

Minion
I didn't say it was hard, just troublesome.

And is to_int("KoLmafia r7643") really 7643 as you suggest? I always assumed that if there were non-numerical portions of a string that it wouldn't just clip them off.
 
Last edited:

lostcalpolydude

Developer
Staff member
Doesn't the CLI command "version" already tell you the current version? You could then check that against a constant in your script :)

I update through subversion, and for some reason mafia still thinks it's on version 7544 according to just about everything that gives an indication from the GUI. At the very least, this proposed function would need a reasonable way for the user to say "Yes, I know what I'm doing and I don't want to update."
 

Veracity

Developer
Staff member
I update through subversion, and for some reason mafia still thinks it's on version 7544 according to just about everything that gives an indication from the GUI. At the very least, this proposed function would need a reasonable way for the user to say "Yes, I know what I'm doing and I don't want to update."
Every time somebody has had this problem, we've said the following:

- Delete src/net/sourceforge/kolmafia/KoLConstants.c
- svn update
- recompile

Do you have private changes to KoLConstants?
 

Grotfang

Developer
And is to_int("KoLmafia r7643") really 7643 as you suggest? I always assumed that if there were non-numerical portions of a string that it wouldn't just clip them off.

I hadn't realised this either, so I though, hmm... let's give this a go. I have a constant chatbot script running, which I renamed chatbot_script123.ash (from chatbot_script). I then used this script:

Code:
void main()
{
	string current_script = get_property( "chatbotScript" );
	int current_string_int = string_to_int( current_script );
	print( current_string_int );
}

I hadn't expected this, but it returned:

Code:
123

So yes. It does indeed look as though string_to_int returns the integers and nothing else.

EDIT: Don't know if this has any relevance at all, but when I used the same script having set my chatbot script back to normal, it returned 0. This means there would be no noticable difference between a string with a 0 in it, and a string with no integers in it. Irrelevant to this topic, of course, but something to bear in mind with this (for me) new found functionality.
 
Last edited:

Catch-22

Active member
Yep, to_int is funny like that :) All it does is strip out any character that is not a number. This is why you can't use it for decimals ("13.5" will return 135, it strips out the dot). If you use it on text with no numbers like "KoLmafia" it will strip everything out and convert the empty string to a 0.
 

Grotfang

Developer
I don't know how broken this is, as I haven't been able to test it a great deal. However, I tried adding:

Code:
params = new Type[] {};

		functions.add( new LibraryFunction( "version", DataTypes.STRING_TYPE, params ) );

and

Code:
public static Value version()

	{

		return new Value( KoLConstants.VERSION_NAME );

	}

To the RuntimeLibrary file. Now, when I type:

Code:
ash version();

into the cli it returns:

Code:
Returned: KoLmafia v13.5

Clearly the code at least semi-works. What I wanted to ask is, how broken is it, and is there any way it can be cleaned up? This is the first time I have a) edited mafia's internal files and b) built a version, so I assume something won't be working properly as a result :rolleyes:

EDIT:

Just to add, I have realised that perhaps a better usage would be:

Code:
return new Value( StaticEntity.getVersion() );

This way, the ASH function should return the same as the same CLI command. I have tested this and it seems to work. However, I have no idea why, but for me getVersion returns as "exported". I have looked in the StaticEntity file and for me revision is null, which should (I think) make mafia use VERSION_NAME instead of revision. I have no idea why this isn't working, but I'm pretty sure it isn't related to my fiddling ;)

(Just checked by commenting out my additions - still comes up as "exported" so isn't my fiddling after all)
 
Last edited:

lostcalpolydude

Developer
Staff member
Every time somebody has had this problem, we've said the following:

- Delete src/net/sourceforge/kolmafia/KoLConstants.c
- svn update
- recompile

Do you have private changes to KoLConstants?

Thanks, it's fixed, and without losing my change to DEFAULT_KMAIL.
 

jasonharper

Developer
Caution - to_int() doesn't just strip out non-digits in two cases: if the string ends in "K" or "M", the value gets multiplied by a thousand or a million. Interestingly, the numeric part of the string gets parsed as a float in that case:
Code:
> ash to_int("1.2m")

Returned: 1200000

> ash to_int("0.0027k")

Returned: 2
 

Grotfang

Developer
if the string ends in "K" or "M", the value gets multiplied by a thousand or a million

If it were a version number though (such as that returned by my soon-to-be-posted-to-Veracity mafia update), it returns as a string first, so that could be stripped before using string_to_int.

Good to know that M and K produce weird results though. Definitely a very useful thing to be aware of before I go rushing in!
 

dj_d

Member
re: k/m, that is truly wacky.

I wish we could get an SVN number for major version releases, though. It would make it a lot easier to specify minimum versions. But thanks loads for putting something together!
 

Grotfang

Developer
Ok. Got it written and sorted now. DoctorRotelle is going to patch it and upload it sometime soon.

The function is version() and returns a string, which is the same as the CLI command produces. Basically, if you have a revision (a daily build) that string comes up in the format "KoLmafia r<build>". If you have a major release, that comes up eg. "KoLmafia 13.5".

If you use

Code:
to_int( version() );

It gives only the number (either build or 135, etc). The K and m in KoLmafia do not confuse it at all. What might give problems are the self-edited versions that have a format of KoLmafia r<build>M

This could be worked around within the script (eg. excise( string , "KoLmafia r" , "M" ); ), so I don't think it will be too troublesome.

If you guys are happy to do so, once DoctorRotelle has posted it up, could you give it a try? I would love to see how it copes on different machines.
 

Bale

Minion
This is amusing, but I still don't see the value of having version(). After all, if the user needs to be warned about mafia needing an upgrade, then the script will die due to not knowing a new function like historical_age even before it can check the version. XD

All this function could be used for is to let the user know that his script WON'T break due to not having upgraded mafia.
 

Grotfang

Developer
This is amusing, but I still don't see the value of having version(). After all, if the user needs to be warned about mafia needing an upgrade, then the script will die due to not knowing a new function like historical_age even before it can check the version. XD

I see what you are getting at, but I am under the impression the intention is simply to provide more useful feedback to the end-user. Instead of telling them their version is too old (especially if they only use major releases) this gives them more positive feedback, perhaps telling them which version is the minimum they should be using and, if they have got a major version instead of a daily build, telling them where to find the newer builds.

Yes, it's not essential. Yes, the same information will be carried in the forum post, but scripts get passed around and not every end user is that discriminating. If there is a way to make their experience simpler (even if it's lowest common denominator stuff) then why should we err from doing it?
 

Bale

Minion
Instead of telling them their version is too old (especially if they only use major releases) this gives them more positive feedback, perhaps telling them which version is the minimum they should be using and, if they have got a major version instead of a daily build, telling them where to find the newer builds.

My point is that won't work. If the version is too old it won't give them that feedback, it will just die without ever running the subroutine that gives them feedback since there's an undeclared function. It will only tell them the minimum version if they are running that minimum version or better. Useless.
 

Grotfang

Developer
For a small period, yes. But what about in three month's time? What about a year's time? Yes, initially it will be just like any other new function. But that is very short term.
 

Bale

Minion
You're not paying attention. I'm not talking about failing to recognize version().

Let's say that there is (someday) a new mafia function called... let's call it win_game(). The script will fail to run because win_game is an unknown function. It will fail even though it recognizes version().

Sorry, but version() is useless. Unless there is a mafia directive that tells mafia to give information about the minimum mafia version to run a script, there's no point because a script cannot handle its own failure.
 

Grotfang

Developer
Let's say that there is (someday) a new mafia function called... let's call it win_game(). The script will fail to run because win_game is an unknown function. It will fail even though it recognizes version().

Ohh, I see. Yes, you are completely correct. Sorry.

Damn your logic! :rolleyes:
 

Catch-22

Active member
Haha, of course. KoLmafia verifies a script before it runs. So we still have a problem..

btw yeah I knew about that to_int feature, just didn't mention it. This is handy, so that you can price your Mr. Accessory at 5m instead of 5000000, etc.
 

jasonharper

Developer
If the goal is simply to print an appropriate message if a script needs a new function, simply declare that function yourself, with the same parameter types and return type as the real function. The body would simply be abort("upgrade, you fool!");, followed by a return of a dummy value if the return type isn't void. If the user has a sufficiently recent mafia version, the built-in function overrides the dummy function. If it's too old, the dummy function gives a meaningful message as it self-destructs on the first call. You don't even need to keep track of what version/revision the function first appeared in.
 
Top