Has something changed with if (!something)

Spiny

Member
Some code I've been using, that has worked fine for weeks, and has not been modified, has recently started printing out error trapping code/fail messages despite successfully executing the condition it is reporting failed. Did something change in regards to checking for things with if (!something)? This seems to be transient, one runthru it works as expected and the next runthru the fail messages are printing despite having been successfully executed. Then another runthru it will be fine again.

Example:

Code:
	if (!autosell(5,$item[awful poetry journal])) {
		print("Error trying to autosell","red");
	}

The successful action occurs actually autoselling the 5 awful poetry journals, I see the amount I'm getting, but the script is following thru and printing Error trying to autosell. This isn't restricted to autosell, it's also affecting !use and !cli_execute(kmail blab x bla || blah), so just wondering if something changed regarding disegarding !something.
 

Spiny

Member
What build did it start happening?

I wish I could tell you... the oddity occurred on the 10th and today, the 12th. Easily there are several builds in a day. The 10th was the first time this occurred.

So I guess we're looking at something that occurred between 7720 and 7734 if something was changed.

Of the builds in that range, I know I d/l'd:

7720, 7723, 7724, 7728, 7729, 7734.

Specific output examples:

Code:
 > Autoselling 25 of 28 awful poetry journal

autosell: 25 awful poetry journal
You gain 3,400 Meat
 > Error trying to autosell 25 awful poetry journal

 > Using 54 of 55 Warm Subject gift certificate

use 54 Warm Subject gift certificate
You gain 24,426 Meat
 > Error trying to use 54 Warm Subject gift certificate

When it isn't buggy, it would look more like:

Code:
 > Autoselling 19 of 69 Angry Farmer candy

autosell: 19 Angry Farmer candy
You gain 2,603 Meat
 > Autoselling 9 of 9 awful poetry journal

autosell: 9 awful poetry journal
You gain 1,224 Meat
 > Autoselling 34 of 34 chaos butterfly

autosell: 34 chaos butterfly
You gain 4,216 Meat
 > Autoselling 10 of 11 disturbing fanfic

 > Using 33 of 33 Warm Subject gift certificate

use 33 Warm Subject gift certificate
You gain 14,706 Meat
 
Last edited:

Alhifar

Member
Are you sure autosell is returning what you think it is? Of the other functions you gave, I know both use() and cli_execute() can return values that are counter-intuitive.
 

Spiny

Member
Are you sure autosell is returning what you think it is? Of the other functions you gave, I know both use() and cli_execute() can return values that are counter-intuitive.

Well to be honest, not certain what autosell is returning. Thought it was returning a boolean as to whether or not something sold, returning true if something sells and false if autosell fails.

But like I said this wasn't restricted to the autosell lines... it also affected the use and the cli_execute (kmail...)

These are all feeding off a map if that makes a difference.
 

Bale

Minion
Well to be honest, not certain what autosell is returning. Thought it was returning a boolean as to whether or not something sold, returning true if something sells and false if autosell fails.

Once upon a time I thought the same thing about use(): that it returned true if it used the specified item and false if it did not. Debugging my script disabused me of that notion. As far as I know, none of those boolean functions that do something with an item have ever had a useful or predictable return value. It would probably be better if they returned nothing, so that you wouldn't make false assumptions.
 
Last edited:

Grotfang

Developer
Well, I've just tested the function, and autosell seems to return true whether or not it actually sells the items in question.

I'm level 7, hardcore and I tried to sell 5 awful poetry journals:

Code:
> ash autosell(5,$item[awful poetry journal]);

Autoselling items to NPCs...
Items sold.
Returned: true

The return from a blue plasma ball (which I do have):

Code:
> ash autosell(1,$item[blue plasma ball]);

Autoselling items to NPCs...
You gain 5 Meat
Items sold.
Returned: true

Can we assume the return from this function is meaningless?

I should add... when I copy and paste the code above into an ash script and call it; without any awful poetry journals in my inventory it reads:

Code:
> call exp.ash

Autoselling items to NPCs...
Items sold.

With the items in my inventory:

Code:
> call exp.ash

Autoselling items to NPCs...
You gain 5 Meat
Items sold.
 
Last edited:

Catch-22

Active member
I think autosell will return 1 if the item can be autosold :) Can't confirm this, due to rollover.
 
Last edited:

holatuwol

Developer
If I remember correctly, item functions return a boolean that indicate whether KoLmafia has an encountered an error state (an error state is one where KoLmafia prints red text that isn't of the "world peace" variety) or a pending state (like an auto-stop condition).

To understand the motivation for why things work this way, it's easiest to think of it as giving scripters the ability to fake a try-catch block. The underlying problem was that KoLmafia would stop executing your script if a pending/error state was encountered without giving users the ability to do extra error handling.

If you add the if(), the true condition is what you do when there is no exception raised by KoLmafia, the false condition is when there is an exception raised by KoLmafia. If you decide not to use if statements, your script will error out immediately.

It's possible that autosell is using a pending state somewhere, which would cause the return value of autosell to be false without any error messages being printed. (On that note, the x of y messages sound like something that should be incorporated back into KoLmafia, I'll add that to my to-do list after I'm done breaking chat.)
 
Last edited:

Bale

Minion
Thank you for that insight holatuwol. It makes me happy no know the sense behind the return value.
 
Last edited:

Bale

Minion
By the way I just tried this

If I have awful poetry journals in my inventory:
Code:
[COLOR="#808000"]> ash if (!autosell(5,$item[awful poetry journal])) print("Error trying to autosell","red");[/COLOR]

Autoselling items to NPCs...
You gain 680 Meat
Items sold.
Returned: false
Placing items into closet...
Requests complete.

If I have no awful poetry journals:

Code:
[COLOR="Olive"]> ash if (!autosell(5,$item[awful poetry journal])) print("Error trying to autosell","red");[/COLOR]

Autoselling items to NPCs...
Items sold.
Returned: false
Works perfectly. It returns a lack of error condition regardless of selling any journals. It didn't sell any, but that's not an error. ;)

Now, how can I cause an error condition on autosell without KoL messing up...
 

Catch-22

Active member
Well, it sounds like more work, but really you should be checking if that amount of items exist first.

I think of it like this, if I'm using the FileSystemObject from the Windows Scripting Runtime Library and I want to delete a file, I need to do this:

Code:
If (FileSystemObject.FileExists("myfile.txt")) Then
    FileSystemObject.Delete("myfile.txt")
Else
    Echo "The file does not exist."
End If

If you try to delete a file that doesn't exist, you'll get a runtime error, so first you have to check if the file exists.

I think it's the same story here, if you want to autosell 5 poetry journals, you should check to see if you have those journals first :)
 
Last edited:
Top