Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Scripting noob needs help

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    12

    Question Scripting noob needs help

    Hey guys,

    I have been playing KOL for a while now and am getting consistent 3-day-runs as I use always the same pulls and almost always the same route.
    Now I want to use a more automated approach, but all ascension scripts I tried do things I do not want or understand (they change my familiars, equip wierd items, etc.).
    I want more control over those things, in the exact order I figured out.


    For starters I need a pulling script to manage my needed items, so I read a bit in the wiki and tried to write a function I could use later in my own ascension-script.
    Would this work?

    Code:
    boolean try_pull(string it, int pull_amount){
    if(storage_amount(it) < pull_amount)
    	{
    		print("Not enough "+it+" in Storage.", "red");
    		if(stash_amount(it) < pull_amount)
    		{
    			print("Not enough "+it+" in Clanstash.", "red");
    			buy_using_storage(pull_amount, it, 75000);
    			take_storage(pull_amount, it);
    		}
    		else
    		{
    			print(+it+" taken from Clanstash.", "green");
    			take_stash(pull_amount, it);
    		}
    	}
    else 
    	{
    		print(+it+" taken fom Storage.", "green");
    		take_storage(pull_amount, it);
    	}	
    print(pulls_remaining() "left.")
    return true;
    As I do not know how to use external sources like text files, yet, I wanted to write:
    It should always pull 3 different items, 1 of each.


    Code:
    void main() {
    it = item1;
    try_pull(it, 1);
    it = item2;
    try_pull(it, 1);
    it = item3;
    try_pull(it, 1);
    
    etc.
    
    return;
    }

    edit: I haven't been programming (C++) for a few years and am more than rusty.
    Last edited by Timbatim; 10-14-2017 at 04:12 PM.

  2. #2
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    727

    Default

    Data Types

    Functions such as storage_amount() & take_storage() etc. are expecting "it" to be the $item[] data type. You are passing in a string type. So you need to convert "it" to item type ( to_item() ) or pass in item type to begin.

  3. #3

    Default

    I'm pretty sure you can't pull from your clan stash while in ronin, so that part of the script won't work.

    Code:
    print(+it+" taken fom Storage.", "green");
    The + at the start breaks that.

  4. #4
    Junior Member
    Join Date
    Oct 2017
    Posts
    12

    Default

    Thanks AlbinoRhino and lostcalpolydude, I wasn't aware of that datatype and the stash does not work in Ronin indeed and is a bit easier.

    Does the to_item function work that way?
    I declare a new local var named it which is emtpy and define it with to_item(it_str).
    The string imported via the try_pull function is renamed it_str, as I am not sure if those two can named equal without being defined in beforehand.


    Code:
    boolean try_pull(string it_str, int pull_amount){
    
    item it = $item[ none ];
    item it = to_item(it_str);
    
    if(storage_amount(it) < pull_amount)
    	{
    		print("Not enough "+it+" in Storage, bought 1.", "red");
    		buy_using_storage(pull_amount, it, 75000);
    		take_storage(pull_amount, it);
            }
    else 
    	{
    		print("1 "+it+" taken fom Storage.", "green");
    		take_storage(pull_amount, it);
    	}	
    print(pulls_remaining() "left.")
    return true;
    
    
    void main() {
    it = item1;
    try_pull(it, 1);
    it = item2;
    try_pull(it, 1);
    it = item3;
    try_pull(it, 1);
    
    etc.
    
    return;
    }

  5. #5
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    727

    Default

    Something like this should work. Some minor differences with what you already have....hopefully they are apparent.

    PHP Code:


    boolean try_pull
    (string it_strint pull_amount)
    {


        
    item it to_item(it_str);


        if(
    storage_amount(it) < pull_amount)
        {
            print(
    "Not enough "+it+" in Storage, bought"+pull_amount+".""red");
            
    buy_using_storage(pull_amountit75000);
            
    take_storage(pull_amountit);
            print(
    pulls_remaining() +" pulls left.")
            return 
    true;
        }
        else 
        {
            print(
    pull_amount+" "+it+" taken fom Storage.""green");
            
    take_storage(pull_amountit);
            print(
    pulls_remaining() +" pulls left.")
            return 
    true;
        }




        print(
    pulls_remaining() +" pulls left.")


    return 
    false;
    }




    void main()
    {    
        
    string i "";

        
    "huge bowl of candy";
        
    try_pull(i1);

        
    "facsimile dictionary";
        
    try_pull(i1);

        
    "disassembled clover";
        
    try_pull(i1);

    Edit: The "return false" is unreachable, i think, at this state of the development. There should probably be more error checking as to whether the purchasing & removing from storage actually succeed, as well.
    Last edited by AlbinoRhino; 10-14-2017 at 06:45 PM.

  6. #6
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    727

    Default

    Here is a slightly more developed version...

    PHP Code:



    boolean try_pull
    (string it_strint pull_amount)
    {

        
    item it to_item(it_str);
        
    string pleft() { return pulls_remaining() +" pulls left."; }
        
        print(
    pleft(), "blue");
        
        
        if    ( 
    pulls_remaining() < pull_amount )
        {
            print(
    "Reducing pull amount to "+pulls_remaining()+".","red");
            
    pull_amount pulls_remaining();
        }
        

        if(
    storage_amount(it) < pull_amount)
        {
            print(
    "Not enough "+it+" in Storage, to pull "+pull_amount+".""red");
            
            
    int gotit buy_using_storage(pull_amountit75000);
            
            if    ( 
    gotit == )
            {
                print(
    "Was unable to buy any "+it"red");
                print(
    pleft(), "blue");
                return 
    false;
            }
            else
            {
                print(
    "Bought "+gotit+" "+it+". Pulling...","green");
                
                if    ( 
    take_storage(gotitit) )
                {
                    print(
    "Pulled "+gotit+" "+it,"green");
                    print(
    pleft(), "blue");
                    return 
    true;
                }
                else
                {
                    print(
    "Unable to pull "+gotit+" "+it,"red");
                    print(
    pleft(), "blue");
                    return 
    false;
                }
            }
        }
        else 
        {
            
            if    ( 
    take_storage(pull_amountit) )
            {
                print(
    pull_amount+" "+it+" taken fom Storage.""green");
                print(
    pleft(), "blue");
                return 
    true;
            }
            else
            {
                print(
    "Unable to pull "+pull_amount+" "+it,"red");
                print(
    pleft(), "blue");
                return 
    false;
            }
        }
    }


    void main()
    {
        foreach 
    i in $strings[
        
    huge bowl of candy,
        
    facsimile dictionary,
        
    disassembled clover,
        ]
        {
            if    ( 
    try_pull(i1) )
            {
                print(
    "Got "+i,"green");
            }
            else
            {
                print(
    "Was unable to get "+i,"red");
            }
        }

    Last edited by AlbinoRhino; 10-15-2017 at 12:59 AM.

  7. #7
    Junior Member
    Join Date
    Oct 2017
    Posts
    12

    Default

    Hey thanks again, I copied your last code and tried to figure out which alterations were made and most importantly why they were made.
    Took me a while, but I have additional questions


    Code:
    int gotit = buy_using_storage(pull_amount, it, 75000);
    What I think it does:
    It creates a new variable named gotit, activates the function and returns 1 for success/0 for failure?
    I mean it does all that in that one line by defining the var?

    edit: Moreso the boolean of the function gets an int, does it work that way?


    Code:
    if    ( take_storage(gotit, it) )
                {
                    print("Pulled "+gotit+" "+it+, "green");
                    //print(pleft(), "blue");
                    return true;
                }
    It can activate the function in the condition for the if-iteration?
    In this case it doesn't need a > < or ==? Why though?
    Last edited by Timbatim; 10-14-2017 at 10:05 PM.

  8. #8
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    727

    Default

    Hey thanks again, I copied your last code and tried to figure out which alterations were made and most importantly why they were made.
    Took me a while, but I have additional questions


    Code:
    int gotit = buy_using_storage(pull_amount, it, 75000);
    What I think it does:
    It creates a new variable named gotit, activates the function and returns 1 for success/0 for failure?
    I mean it does all that in that one line by defining the var?

    edit: Moreso the boolean of the function gets an int, does it work that way?


    Code:
    if    ( take_storage(gotit, it) )
                {
                    print("Pulled "+gotit+" "+it+, "green");
                    //print(pleft(), "blue");
                    return true;
                }
    It can activate the function in the condition for the if-iteration?
    In this case it doesn't need a > < or ==? Why though?
    Originally Posted by Timbatim View Post

    buy_using_storage()

    If you click the link above you will see that there is both a boolean and an integer version of this ASH function. When you specify a max price (as you did in your original code) this function returns an integer...the quantity that were obtained. So we created the variable "gotit" to capture how many were obtained.


    http://wiki.kolmafia.us/index.php?title=Take_storage

    The take_storage() ASH function returns a boolean... " if ( take_storage(gotit, it) )" ...is only going to be TRUE or FALSE. If TRUE, the bracketed code will run. If FALSE, execution will continue at the corresponding "else".

    Edit: There were a couple of minor errors in the code I posted (I didn't actually try to run it.) Corrected the above post (#6) and confirmed that it works as intended. Sorry for posting broken code !
    Last edited by AlbinoRhino; 10-15-2017 at 01:21 AM.

  9. #9
    Junior Member
    Join Date
    Oct 2017
    Posts
    12

    Default

    Ah yes, I see the return of an int. What I meant was another thing, too.

    Code:
    int gotit = buy_using_storage(pull_amount, it, 75000);
    We get an int and put it to gotit. But do actually use the function as in really buying something? It seems it is just a check if everything "could" be bought.


    Code:
    if    ( take_storage(gotit, it) )
                {
                    print("Pulled "+gotit+" "+it+, "green");
                    //print(pleft(), "blue");
                    return true;
                }
    When I try to verify the .ash file in the cli command, I always get a "value expected", I assume it is because nothing can really be bought by verifying so there is no real gotit.

  10. #10
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    727

    Default

    The function DOES execute and "gotit" will be how many were obtained...which is the return value of buy_using_storage() in this case.


    "value expected"
    You must still be using an old copy of the code I posted.
    Take the extra "+" off after the "+it".
    Last edited by AlbinoRhino; 10-16-2017 at 09:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •