line break in strings and other problems...

Kaffeetrinken

New member
Hi! Yesterday I wrote my first ash script for autoselling my farmed stuff etc.
Right now I am trying to enhance said script by constructing a string that eventually will contain some sort of report on what the script did. I have run into two problems:

1. I am having trouble adding line breaks to the string, e.g:
Code:
void main()
{
string test = "a \n b";
print(test);
}
will produce: "a b" in CLI

2. Is there a way of tracking things like the amount of meat gained from:
Code:
use( 1, $item[Warm Subject gift certificate])
or the smash results of:
Code:
cli_execute("smash happiness")
?
I know CLI displays the results but i haven't figured out how I can make use of that.

Please excuse if these answers could have been answered if I had been more patient with the forum search and thanks in advance for any help.

Bonus Questions:
1. Is there an ash equivalent of CLI's smash?
2. Is there any way of using the malus, CLI or ash?
 

Theraze

Active member
For number 2, the easiest way to do it would be to cheat...
PHP:
ashq int meatamount = my_meat(); int count = item_amount($item[Warm Subject gift certificate]); use(count, $item[Warm Subject gift certificate]); print("You gained an average of " + ((my_meat() - meatamount) / count) + " for each of your " + count + " gift certificates.");

All that 'use' returns is whether or not to continue automation, unfortunately. That makes it a touch difficult to interpret directly.

Regarding smashing happiness you COULD maybe do int [item] currentinv = get_inventory() and then do an int [item] postinv = get_inventory() after and compare them... but not really sure of the best way to do their comparisons. Verified that int [item] is the proper bit for this though...
> ash int [item] currentinv = get_inventory();

Returned: aggregate int [item]
Degrassi Knoll shopping list => 1
(List continues, but nobody really cares about the junk in my inventory, so...)

However, this MIGHT accomplish this...
PHP:
ashq int [item] currentinv = get_inventory(); int [item] postinv = get_inventory(); foreach i1,c1 in postinv foreach i2,c2 in currentinv if (i2 == i1){if (c2 != c1) print(i2 + ": " + (c2 - c1));}

Basically, the currentinv part goes at the start of the script, then all of the rest of it goes after modifications have happened. It SHOULD print out like:
Warm Subject gift certificate: -1

Could also add in meat change by doing the following script together...
PHP:
ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i1,c1 in postinv foreach i2,c2 in currentinv if (i2 == i1){if (c2 != c1) print(i2 + ": " + (c2 - c1));}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));
 
Last edited:

xKiv

Active member
1. I am having trouble adding line breaks to the string, e.g:

I think you *might* want to do something like
Code:
print_html("a<br>b");

1. Is there an ash equivalent of CLI's smash?

I don't think so ... only cli_execute("smash " + number + " "+ item).

2. Is there any way of using the malus, CLI or ash?

Just smash the powders/nuggets. That will malus then one step up.
 

Theraze

Active member
Actually, the \n will work fine with print_html as well...
> ashq print_html("Starting script.. \n Testing line breaks.");

Starting script..
Testing line breaks.

Made a shiny new alias to track changes... trackitems. Actually also tracks meat, but...
alias trackitems => ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); cli_execute("%%"); int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i1,c1 in postinv foreach i2,c2 in currentinv if (i2 == i1){if (c2 != c1) print(i2 + ": " + (c2 - c1));}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));

Basically, trackitems <whatever else you wanted to do> and it'll run it through the CLI. As it's passing it through the CLI again, you can use other aliases and it'll only post if something actually happened.
 
Last edited:

Kaffeetrinken

New member
Wow! Your solution is much more elegant than what I had in mind, Theraze.
You mixed up c1 and c1 in the print statement though.
It displays item losses as a positive int etc.

PHP:
alias trackitems => ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); cli_execute("%%"); int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i1,c1 in postinv foreach i2,c2 in currentinv if (i2 == i1){if (c2 != c1) print(i2 + ": " + (c1 - c2));}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));
should be correct.

Thanks a lot to both of you!
 

Theraze

Active member
Oh... genius. I swapped i1 and i2 as I was going through. I'd suggest actually changing the postinv to i2/c2 and currentinv to i1/c1 since it comes first.

The other issue with this is that it doesn't do too well with completely new items, or if you use up an item fully or the like... if the item isn't in inventory both before and after, i2 will never equal i1. Hmm... could try doing this, I suppose...
PHP:
alias trackitems => ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); cli_execute("%%"); int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i2,c2 in postinv{boolean itemfound = false; foreach i1,c1 in currentinv if (i2 == i1){itemfound = true; if (c2 != c1) print(i2 + ": " + (c2 - c1));}if (!itemfound) print(i2 + ": " + c2);}foreach i1,c1 in currentinv{boolean itemfound = false; foreach i2,c2 in postinv if (i2 == i1){itemfound = true;}if (!itemfound) print(i1 + ": " - c1);}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));

Basically, added in a bool check for the item being found, with it being set to false on each item. If it's not found in postinv, display it as a negative amount. If it's not found in currentinv, display it as a positive amount.

Or that's how it's supposed to work. Making it properly parse required an extra running through the (old) inventory to verify that everything exists in current as well. Should work... can't test until tonight. Unless I actually have a character with certificates or the like... hmm... or i suppose could try just autoselling something. *ponders*

> trackitems sell 1 meat paste

Autoselling items to NPCs...
You gain 10 Meat
Items sold.
meat paste: -1
Meat: 10

Yeah... runs through each item in inventory repeatedly... not sure if I can just do something like if (postinv[i2] =! currentinv[i2])... does look like it works though. Faster too, since it eliminates the parsing of inventory through inventory... Also fixed a bug with selling items. Should work now, and without the lag regardless of how large your inventory is.

PHP:
alias trackitems => ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); cli_execute("%%"); int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i2,c2 in postinv{if (postinv[i2] != currentinv[i2]) print(i2 + ": " + (postinv[i2].to_int() - currentinv[i2].to_int()));} foreach i1,c1 in currentinv{if (postinv[i1] == 0) print(i1 + ": " + (-c1));}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));

> trackitems create 1 meat paste

Creating 1 meat paste...
You acquire an item: meat paste
You lose 10 Meat
Successfully created meat paste (1)
meat paste: 1
Meat: -10

> trackitems autosell 1 meat paste

Autoselling items to NPCs...
You gain 10 Meat
Items sold.
meat paste: -1
Meat: 10
 
Last edited:

slyz

Developer
I think
PHP:
print(i1 + ": " - c1);
should be
PHP:
print(i1 + ": -" + c1);

It's a nice alias, but since the gCLI already prints most of the changes in items/meat, I don't know if it will see a lot of use ^^
 

Theraze

Active member
I actually fixed that bug (and several others, including some very unoptimal code) in the post above.

The point is that it doesn't have to print out... it's printing because it can. But you could use the guts of it for anything...

And actually, using this to track meat/items gained on running your farming script, for example, could be useful. If you just want it to display, then trackitems castle_farming would run your script named castle_farming, and at the end, give you the total item and meat change... Or if you're feeling somewhat more detailed, you could rework it to map the changes to a file, and watch the effects over time, or... anything you want, really.

As I was writing this, I think I'll be using this integrated into my normal adventuring checks. trackitems adventure 20 haunted kitchen will make grabbing lowbie HC BM foods significantly easier, as I'll get the exact change in items. Also, can do trackitems eatdrink and find out how many ingredients it's actually using... :)
 

Theraze

Active member
I was thinking about the trackitems alias and try/finally just occurred to me... implemented that into trackitems, and now even if I cancel partially through an execution, I get to see my item/meat change. So here's an updated version of trackitems.
PHP:
alias trackitems => ashq int [item] currentinv = get_inventory(); int currentmeat = my_meat(); try{cli_execute("%%");}finally{ int [item] postinv = get_inventory(); int postmeat = my_meat(); foreach i2,c2 in postinv{if (postinv[i2] != currentinv[i2]) print(i2 + ": " + (postinv[i2].to_int() - currentinv[i2].to_int()));} foreach i1,c1 in currentinv{if (postinv[i1] == 0) print(i1 + ": " + (-c1));}if (postmeat != currentmeat) print("Meat: " + (postmeat - currentmeat));}
 
Top