Degrassi knoll general store: added items Version 2 more items!

Version 2 is here!
Differences:
1: Added Items which can be smithed by Innabox, and require only NPC items, or meat stacks/dense meat stacks.
2: split the page a little to make finding desired item faster.





This script was re-worked by Holatuwol, and attached to their post also.

The script adds items like meat engines and meat maid bodies to the degrassi knoll general store. Items which can be made completely from NPC items. I have not added the smithable NPC items yet, but it's still useful for those who ascend manually, but make use of the relay browser enhancements built into Kolmafia. It will buy the needed components, and put together the item when you attempt to buy a NPC creatable item.

Remember to create a "Relay" folder in the directory kolmafia is in, and put this script in that "Relay" folder.

Original post follows:


I would like to add the following:
PHP:
<tr><td valign=center><input type=radio name=whichitem value=248></td><td>[img]http://images.kingdomofloathing.com/itemimages/engine.gif[/img]</td><td valign=center><a onClick='javascript:descitem(465274324)'>[b]meat engine[/b]</a></td><td>180 Meat</td></tr>
And a few more to the degrassi knoll general store, and have the script handle buying individual components and building the meat engine or other item. I haven't tried it yet, but I foresee a string closing problem which I have encountered and worked around in the past. I don't see a simple workaround in this case though.

Any suggestions?
Have I missed a change to scripting which might effect this situation?
 

Attachments

  • store.ash
    14.8 KB · Views: 71

holatuwol

Developer
Re: String closing and Degrassi knoll general store

I'm not sure I understand what you mean? Do you mean including quotes in a string? For that, just use backslash. If you mean something else, would you mind providing an example?
 
Re: String closing and Degrassi knoll general store

[quote author=holatuwol link=topic=1137.msg5363#msg5363 date=1186244680]
I'm not sure I understand what you mean? Do you mean including quotes in a string? For that, just use backslash. If you mean something else, would you mind providing an example?
[/quote]

Including quotes in a string is what I meant.

For simplicity sake how about making this work:
print("pet rock "Snooty" disguise");

print("pet rock \"Snooty\" disguise"); is the correct way?

I'm not meaning sarcasm here, and hope it wont be taken that way. I just never knew there was a way to put quotes in a script.
 

holatuwol

Developer
Re: String closing and Degrassi knoll general store

[quote author=efilnikufecin link=topic=1137.msg5368#msg5368 date=1186250725]
For simplicity sake how about making this work:
print("pet rock "Snooty" disguise");
print("pet rock \"Snooty\" disguise"); is the correct way?
[/quote]

Correct.
 
Re: String closing and Degrassi knoll general store

[quote author=holatuwol link=topic=1137.msg5369#msg5369 date=1186251595]
Correct.
[/quote]

Thank you, now off to work on a script for a bit till I have to do other things!
 
Re: String closing and Degrassi knoll general store

I'm getting
No closing " found (store.ash, line 20)

Line 20 contains several ; in a string. I tried \; like with " but I still get the error message.
 

Attachments

  • store.ash
    3.8 KB · Views: 73

holatuwol

Developer
Re: String closing and Degrassi knoll general store

Looks like the // is being treated as a comment (you know, in http://images.kingdomofloathing.com/).  I've put this on my to-fix list for later, but ... yeah.

For reference, if you ever need something from the KoL images server, it's sufficient to use /images/itemimages.  KoLmafia will automatically download the needed file and transmit it to your browser.


Okay, this should be fixed.
 
Re: String closing and Degrassi knoll general store

Thanks Holatuwol!

I'm moving on with the script, and it's nearing functionality at which point I will move on to simplify the script. Problem is now I am getting an error message that doesn't make sense to me.
Index has wrong data type (store.ash, line 153)
Line 153 is now:
replace_string( text, ItemImageReplace, NewGnollItems[to_produce].ImageName );

Where text is a buffer, ItemImageReplace and NewGnollItems[to_produce].ImageName are strings.

I'm using build 4644 now, but this also happened in 4639 if that matters.

Current state of script attached.

Edit: I just noticed we have an equal number of posts now. ;D
 

Attachments

  • store.ash
    8.2 KB · Views: 73

Veracity

Developer
Staff member
Re: String closing and Degrassi knoll general store

[quote author=efilnikufecin link=topic=1137.msg5391#msg5391 date=1186403423]
Problem is now I am getting an error message that doesn't make sense to me.
Index has wrong data type (store.ash, line 153)
Line 153 is now:
replace_string( text, ItemImageReplace, NewGnollItems[to_produce].ImageName );

Where text is a buffer, ItemImageReplace and NewGnollItems[to_produce].ImageName are strings.[/quote]
It's a compile-time error complaining about your "index" - the variable you are indexing a map with.
The only "index" on the line you reference is "to_produce", used to index "NewGnollItems".

Your script says:

ItemData [item] NewGnollItems;

...so you want an item as the index. But, I see:

int to_produce

as the function parameter.

You might consider using to_item( to_produce ).

(You might also consider using more indentation; when I see code at the left margin, I assume it's top-level code - not inside a block, like a function body. Not that it affects execution. Just readablility.)
 
Re: String closing and Degrassi knoll general store

Thank you Veracity, I have to admit that was pretty dumb of me. I wasn't looking at the parameter function call, just the main function call.

New problems

In the relay browser:
I don't know how to word this problem, or describe it except to say that on first visit the general store is as expected showing the extra items I am trying to add and everything. The second visit it shows them twice. The third 3 times, the fourth 4 times, and so on.

When I try to buy something I always get "A fatal error has occurred. Please report this to the script repository forums." whether I have meat or not. That message I don't intend to ever show. Without meat I should get the message "You can't afford that item." the same as kol would display. With meat I should get a message very similar to what kol would say when acquiring the items, and the correct meat should be gone while the item should be there.

In Kolmafia:
When I try to buy a sprocket assembly with or without meat I get:
Verifying ingredients for sprocket assembly...
Searching for items...
Desired purchase quantity not reached (wanted 1, got 0)
Searching for items...
Desired purchase quantity not reached (wanted 1, got 0)
You need 1 more sprocket to continue.

Expected:
You acquire an item sprocket
You acquire an item spring
You acquire an item sprocket assembly

This doesn't seem to be something which is an error on my part, but it could be. Could someone please check into it and see what you come up with?
 

Attachments

  • store.ash
    8.3 KB · Views: 82

holatuwol

Developer
Re: String closing and Degrassi knoll general store

PHP:
//here is where the fix for travoltan trousers goes.
if(my_meat() > (NewGnollItems[to_produce.to_item()].price * quant))
{
	buffer temp = Generate_Initial();
	int search_index = temp.index_of( "<Center>" ) + 8;
	temp.insert( search_index, ErrorSTR );
	return temp;
}

You should probably change the greater-than to a less-or-equal.

Edit 1: Or probably just strictly less-than.

Edit 2: I strongly recommend just marking .ash scripts as Java/PHP/Javascript in your programming editor of choice, especially if you're going to do any relay override scripts.  You'll get a lot of the right syntax highlighting and the auto-indentation saves you a lot of hassle.  It also makes things a lot easier to read for later review and debugging. :)

Edit 3: And ... while it's technically correct to indent each if under each else, it's also near unreadable as the indentation goes really high.  Just type "else if" on the same line and don't add extra indentation.  It really, really helps when reading over scripts.


[quote author=efilnikufecin link=topic=1137.msg5395#msg5395 date=1186434268]
I don't know how to word this problem, or describe it except to say that on first visit the general store is as expected showing the extra items I am trying to add and everything. The second visit it shows them twice. The third 3 times, the fourth 4 times, and so on.[/quote]

Looks like a bug with buffers.  Rats.  I'll poke at it.

Edit 1: Okay, looks like I've got it fixed.
 

Veracity

Developer
Staff member
Re: String closing and Degrassi knoll general store

If we're giving "readability" advice, rather than:

Code:
        if(result[tobuy] = quant)
                return true;
        else
                return false;

I prefer:

Code:
        return ( result[tobuy] = quant );

And, if you want it to actually do what you INTEND for it to do, I'd go so far as to say:

Code:
        return ( result[tobuy] == quant );

;)

Edit: I find it interesting that the "if" statement allowed a non-boolean expression as the conditional.
I think that's a bug. And I expect that while and repeat have the same bug.
 

holatuwol

Developer
Re: String closing and Degrassi knoll general store

[quote author=Veracity link=topic=1137.msg5398#msg5398 date=1186450019]
Edit: I find it interesting that the "if" statement allowed a non-boolean expression as the conditional.
I think that's a bug. And I expect that while and repeat have the same bug.
[/quote]

Actually, a lot of people were having problems with == (preferring = instead for equality) so when the parser knows it's not an assignment, KoLmafia treats "=" as the equality check operator, not the assignment operator.  You can verify by typing something like this:


PHP:
int i, j;
i = j = 1;

The above reports an error, because the second "=" is treated as an equality rather than a second assignment and you can't assign a boolean to an int.  You lose a little bit of the readability advantage, and you lose the convenience of chaining assignments together, but it seems to make scripting newbies happy.
 

Veracity

Developer
Staff member
Re: String closing and Degrassi knoll general store

[quote author=holatuwol link=topic=1137.msg5399#msg5399 date=1186451171]
You lose a little bit of the readability advantage, and you lose the convenience of chaining assignments together, but it seems to make scripting newbies happy.[/quote]

If ASH said "if needs a boolean expression as its conditional and you supplied an int" - i.e., if it actually checked at compile time, rather than mysteriously failing at run time (which is what it looks like it does now, when your numeric expression fails to evaluate to exactly TRUE_VALUE), I don't see how that is less "newbie friendly".

I still think this is a bug.
 
Re: String closing and Degrassi knoll general store

Obviously I needed to take a break from it yesterday. When I went back to work on it I saw the ever so obvious. Where I meant to use the string Fail_no_meat I instead used the string ErrorStr. This was on top of the other problems noted.

the = vs == thing...I spent a long time fixing scripts which used = where they should have used ==, and so has a lot of others. Fact is I keep trying to do it myself, so now I just leave it though I do think that failing without an error message is a bug.

As for format...sorry for my lack of using the preferred format for java/ash. I keep using the format I use with Pascal.

Upgraded to version 4661. Error message:
Java heap space
 

Attachments

  • store.ash
    8.3 KB · Views: 69

Veracity

Developer
Staff member
Re: String closing and Degrassi knoll general store

[quote author=efilnikufecin link=topic=1137.msg5402#msg5402 date=1186492752]
the = vs == thing...I spent a long time fixing scripts which used = where they should have used ==, and so has a lot of others. Fact is I keep trying to do it myself, so now I just leave it though I do think that failing without an error message is a bug.[/quote]

Turns out it did give a compile-time error if you used an int in the conditional: "Cannot apply int to to boolean at line ...", where the line number was the line number of the end of the scope, not the line number of the conditional itself.

That seems more than a little obscure, so I stuck in more informative error messages that trigger immediately when a non-boolean conditional expression is parsed.
 

holatuwol

Developer
Re: String closing and Degrassi knoll general store

[quote author=efilnikufecin link=topic=1137.msg5402#msg5402 date=1186492752]
Upgraded to version 4661. Error message:
Java heap space
[/quote]

My mistake, variables were already getting initialized properly, but buffers need to constantly be re-initialized rather than reusing the same initial value.  Also, a suggestion -- treat records like objects that can get "initialized".  For example, that huge data entry block could get really tedious, especially if you start adding more stores, and you can simplify it like so:


PHP:
ItemData [item] NewGnollItems;
void initialize( ItemData this, string Price, string DescID, String ImageName, string Plural )
{
	this.Price = Price;
	this.DescID = DescID;
	this.ImageName = ImageName;
	this.Plural = Plural;
}

NewGnollItems[$item[sprocket assembly]].initialize( "40", "362582736", "assembly1.gif", "sprocket assemblies" );
NewGnollItems[$item[cog and sprocket assembly]].initialize( "60", "524880668", "assembly2.gif", "cog and sprocket assemblies" );
NewGnollItems[$item[full meat tank]].initialize( "120", "175722264", "tank.gif", "full meat tanks" );
NewGnollItems[$item[meat engine]].initialize( "180", "465274324", "engine.gif", "meat engines" );
NewGnollItems[$item[Gnollish autoplunger]].initialize( "260", "792002723", "autoplunge.gif", "Gnollish autoplungers" );
NewGnollItems[$item[meat maid body]].initialize( "260", "185286006", "maidbody.gif", "meat maid bodies" );


I did a few simplications to your script as I was figuring out what was causing that heap error, such as increasing indentation (to make code blocks easier to see) and making variable names consistent.  Those modifications are attached.

Also, the idea of adding creatable items to the purchase list based on the items available in a store ... I really like it.  Why force people to use the acquire CLI command when they can just click on things in browser to get the same effect?  It's not as easy to implement KoLmafia-side as it is to implement in ASH, but I'll think over the idea.




I've also added a new get_ingredients method and an is_npc_item method, which may help in simplifying this script a little further, in the event that you wish to do so and maybe allow you to easily extend its functionality anywhere else you might want to extend it.
 

Attachments

  • store.ash
    6.7 KB · Views: 89
Re: String closing and Degrassi knoll general store

[quote author=holatuwol link=topic=1137.msg5405#msg5405 date=1186516177]
My mistake, variables were already getting initialized properly, but buffers need to constantly be re-initialized rather than reusing the same initial value. Also, a suggestion -- treat records like objects that can get "initialized". For example, that huge data entry block could get really tedious, especially if you start adding more stores, and you can simplify it like so:
[/quote]
I couldn't think of any other stores which had items which I would want to add right off, but I do prefer your way of writing it. I've actually used your way before, just this time I wasn't thinking much about it.

[quote author=holatuwol link=topic=1137.msg5405#msg5405 date=1186516177]
I did a few simplications to your script as I was figuring out what was causing that heap error, such as increasing indentation (to make code blocks easier to see) and making variable names consistent. Those modifications are attached.
[/quote]

Thanks! I see you eliminated the knoll_buy function, but not the chain of create functions? I'm kind of curious why not the chain?

[quote author=holatuwol link=topic=1137.msg5405#msg5405 date=1186516177]
Also, the idea of adding creatable items to the purchase list based on the items available in a store ... I really like it. Why force people to use the acquire CLI command when they can just click on things in browser to get the same effect? It's not as easy to implement KoLmafia-side as it is to implement in ASH, but I'll think over the idea.
[/quote]

I kind of wonder why it wouldn't be feasible to have a second folder called Default which would be created by kolmafia inside the html folder and contain html over-ride script which would actually be packaged with kolmafia? The HTML folder could continue to be checked first, if nothing is found, then the default folder. Once done, you could easily write up an ash html mod script, then I could go and modify it to my taste and save it in the html folder, and post my mods here to see if you like the idea. You could also take scripts others have written and add them seemingly easily.
 

holatuwol

Developer
Re: String closing and Degrassi knoll general store

[quote author=efilnikufecin link=topic=1137.msg5408#msg5408 date=1186519239]
Thanks! I see you eliminated the knoll_buy function, but not the chain of create functions? I'm kind of curious why not the chain?
[/quote]

I had no idea why you had so many extra functions, but it seemed pretty clear that all your knoll_buy function was doing was exactly what the buy function would do.  I only did enough simplification to understand what you were doing.



[quote author=efilnikufecin link=topic=1137.msg5408#msg5408 date=1186519239]
I kind of wonder why it wouldn't be feasible ...
[/quote]

ASH overrides will be made opt-in (off by default) before release, because there's a definite performance hit just for the check and I don't expect this feature to be used by that many people. Having any built-in KoLmafia features depend on that performance hit isn't sensible. Also, as you've discovered, writing relay override scripts is tedious and difficult to debug, so I don't expect many people to dive in and try it.
 
Re: String closing and Degrassi knoll general store

[quote author=holatuwol link=topic=1137.msg5413#msg5413 date=1186523836]


I had no idea why you had so many extra functions, but it seemed pretty clear that all your knoll_buy function was doing was exactly what the buy function would do. I only did enough simplification to understand what you were doing.
[/quote]
knoll_buy was actually blocking the buy command from equipping travoltan trousers. Trying to keep true to the price listed in the store.
[quote author=holatuwol link=topic=1137.msg5413#msg5413 date=1186523836]
ASH overrides will be made opt-in (off by default) before release, because there's a definite performance hit just for the check and I don't expect this feature to be used by that many people. Having any built-in KoLmafia features depend on that performance hit isn't sensible. Also, as you've discovered, writing relay override scripts is tedious and difficult to debug, so I don't expect many people to dive in and try it.
[/quote]

The performance issue I can understand. I kind of hope more people will write up relay over-ride scripts though. Yes it was difficult, but I am going to enjoy the end result and I think the next try will be easier because of the experience.

I was thinking of maybe adding some text in to go with this little addition. Maybe something about Godot's Delivery Service making the added items possible.
 
Top