Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 23

Thread: Checking for items in Hagnks

  1. #11
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,722

    Default

    get_storage()[it] returns a true or false.
    Originally Posted by Pazleysox View Post
    That's weird, because it seems to be a syntax error on my end.

    (I had to use instead: ash int[item] i=get_storage(); i[$item[...]]
    (and it returns the same (correct) number as storage_amount($item[...]))

  2. #12
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    256

    Default

    [CODE]


    edit:
    or you could add a

    print(counter);

    line to your function, and it will print the value each time it is " called ".
    Originally Posted by AlbinoRhino View Post
    I'm even more confused than before. LOL I guess I should leave this stuff to the experts, and only dabble when I can figure it out!

  3. #13
    Senior Member ckb's Avatar
    Join Date
    Mar 2006
    Posts
    744

    Default

    I'm even more confused than before. LOL I guess I should leave this stuff to the experts, and only dabble when I can figure it out!
    Originally Posted by Pazleysox View Post
    Maybe if you describe what you want your code to do, we can help guide you through it, and develop a script to do what you need.

  4. #14
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    705

    RSS

    int item_count() < function will return an integer, function is named 'item_count()'
    {
    item x = $item[knob goblin firecracker]; < 'x' is the item to count
    int counter = storage_amount( x ); < 'counter' is the storage amount of ' x'
    < 'counter' now has a value we can do something with

    < AFTER 'counter' has a value, and BEFORE we exit the function we can print the value

    print("You have "+counter+" of "+x+" in Hagnk's.");

    return counter; < exit the function and 'return' to the place in the code that the function was called from
    }


    < somewhere later in the script,

    item_count();

    < the function has been called, the code it contains will run. The code contains a 'print()' line. The storage_amount and name of the item will be printed.
    Last edited by AlbinoRhino; 07-19-2017 at 05:13 PM.

  5. #15
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    256

    Default

    int item_count() < function will return an integer, function is named 'item_count()'
    {
    item x = $item[knob goblin firecracker]; < 'x' is the item to count
    int counter = storage_amount( x ); < 'counter' is the storage amount of ' x'
    < 'counter' now has a value we can do something with

    < AFTER 'counter' has a value, and BEFORE we exit the function we can print the value

    print("You have "+counter+" of "+x+" in Hagnk's.");

    return counter; < exit the function and 'return' to the place in the code that the function was called from
    }

    < somewhere later in the script,

    item_count();

    < the function has been called, the code it contains will run. The code contains a 'print()' line. The storage_amount and name of the item will be printed.
    Originally Posted by AlbinoRhino View Post
    Wow, this looks so easy now that it's spelled out for me (duh). I took this, and ran it, and (of course) it worked perfect. Now I can work on my script! (yay) (I would put if in here now, but...) WHEN I run into more trouble, I'll ask here again. Thank you so much for your help. I greatly appreciate it.

    Maybe if you describe what you want your code to do, we can help guide you through it, and develop a script to do what you need.
    Originally Posted by ckb View Post
    Lol, AlbinoRhino just spelled it out for me. I'm n00bish when it comes to scripting. I usually bully my way through what I want, but I have enough knowledge to do very simple things.

    Next Question: Is it possible to do a search for multiple items at once?
    Code:
    {   int[item] inventory = get_storage() ;
    	foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio]
       if ( inventory[it] >= 1 ) 
          print ("You have " + it, "green");
    	else print ("You don't have " + it);   }
    kind of like this code does, but with a count for each item?

    Code:
    void main()
    {
    int item_count(){
    item x = $item[knob goblin firecracker];
    int counter = storage_amount( x ); 
    print("You have "+counter+" of "+x+" in Hagnk's.");
    
    return counter; 
    }
    item_count();
    {
    int item_count(){
    item x = $item[8-ball];
    int counter = storage_amount( x ); 
    print("You have "+counter+" of "+x+" in Hagnk's.");
    
    return counter; 
    }
    item_count(); 
    
    }}
    I know this way works, but is there a simpler way to do this?

    Edit:
    It looks like from Darzil's first post, there *IS* a way to do it. I would have to map what I'm looking for. I'll work on this.
    Last edited by Pazleysox; 07-19-2017 at 07:46 PM.

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

    Default

    The code you have here:

    PHP Code:
    {   int[iteminventory get_storage() ;
        foreach 
    it in $items[8-ball3-ball4-balltalisman of baio]
       if ( 
    inventory[it] >= 
          print (
    "You have " it"green");
        else print (
    "You don't have " it);   } 

    int[item] inventory = get_storage() ;
    ...is most of the way there. get_storage() returns a map of ITEM_AMOUNT[item]. You have named that map 'inventory'.


    < a foreach loop will go through each key in the map (in this case that map has [item] keys)

    foreach i in inventory <i.e. each item in my map (in this case it's actually items in storage, not inventory)

    foreach i in inventory
    {
    print(i + " " + inventory[i]);
    <--- print the 'key' (an item 'i') and the value associated with that key (in this case the amount of i in storage ) in the form MAP_NAME[key] --- so --- ' inventory[i] ' represents the storage amount for any particular item ' i ' )
    }

    The above should list everything in Hagnk's along with the amount Hagnk is holding for you.


    Keep at it ! It all gels together in the end !
    Last edited by AlbinoRhino; 07-19-2017 at 09:18 PM.

  7. #17
    Senior Member ckb's Avatar
    Join Date
    Mar 2006
    Posts
    744

    Default

    You can get data from functions, and also pass them data.
    A modification of your item_count() function might take the item as input, and print the amount you have in storage. You return an int of the quantity, but you are not using it in your example.
    Order of your function definitions is important. Usually, you define your individual utility functions, then call them from a main() statement.

    Here is an example of a modified item_count() that takes an item as an argument, prints the info, then returns an int of the quantity:
    PHP Code:
    int item_count(item it) {
        
    int counter storage_amount(it); 
        print(
    "You have "+counter+" of "+it+" in Hagnk's.");
        return 
    counter

    We can use this new function for multiple items, calling it multiple times in a loop. We define that function first, then call it from main(). For fun and education, I added a new variable that sums the total number of items checked and prints that at the end.

    PHP Code:
    int item_count(item it) {
        
    int counter storage_amount(it); 
        print(
    "You have "+counter+" of "+it+" in Hagnk's.");
        return 
    counter
    }

    void main() {
        
    int xx 0;
        foreach 
    it in $items[8-ball3-ball4-balltalisman of baio] {
            
    xx xx item_count(it);
        }
        print(
    "You have a total of "+xx+"items!");

    Yea! Scripting is fun!
    Last edited by ckb; 07-19-2017 at 10:05 PM.

  8. #18
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    256

    Default

    The code you have here:

    PHP Code:
    {   int[iteminventory get_storage() ;
        foreach 
    it in $items[8-ball3-ball4-balltalisman of baio]
       if ( 
    inventory[it] >= 
          print (
    "You have " it"green");
        else print (
    "You don't have " it);   } 

    int[item] inventory = get_storage() ;
    ...is most of the way there. get_storage() returns a map of ITEM_AMOUNT[item]. You have named that map 'inventory'.


    < a foreach loop will go through each key in the map (in this case that map has [item] keys)

    foreach i in inventory <i.e. each item in my map (in this case it's actually items in storage, not inventory)

    foreach i in inventory
    {
    print(i + " " + inventory[i]);
    <--- print the 'key' (an item 'i') and the value associated with that key (in this case the amount of i in storage ) in the form MAP_NAME[key] --- so --- ' inventory[i] ' represents the storage amount for any particular item ' i ' )
    }

    The above should list everything in Hagnk's along with the amount Hagnk is holding for you.


    Keep at it ! It all gels together in the end !
    Originally Posted by AlbinoRhino View Post
    This s great! I didn't realize it would be that easy. Script works great so far!

    Next issue:
    Code:
    	if ((it) > 0)
    	{
    	print ("You have " + it + " " + inventory[it],  "green");
    	}
    How can I make this work? IE If there is 0 in storage, it won't printout anything...

  9. #19
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    705

    Default

    This s great! I didn't realize it would be that easy. Script works great so far!

    Next issue:
    Code:
        if ((it) > 0)
        {
        print ("You have " + it + " " + inventory[it],  "green");
        }
    How can I make this work? IE If there is 0 in storage, it won't printout anything...
    Originally Posted by Pazleysox View Post
    PHP Code:
    foreach i in inventory
    {
    print(
    " " inventory[i]);   <--- ' inventory[i] ' represents the storage amount for any particular item ' i '

    So...

    PHP Code:
    foreach i in inventory
    {
      if ( 
    inventory[i] > )     <--- ' inventory[i] ' represents the storage amount for any particular item ' i '
      
    {
      print(
    " " inventory[i]);
      }

    ... should print any item with a storage amount > 0. However, get_storage() should only return items where that is true. Which makes me think you are no longer using get_storage(). In which case I need to see more of your code than you have posted to be sure... but generally ...

    if ( item_amount(it) > 0 ) {} <---- Items in inventory

    or

    if ( storage_amount(it) > 0 ) {}

    or

    if ( available _amount(it) > 0 ) {} <---- Items that are ' available ' to you according to the game state and your autoSatisfy settings.
    Last edited by AlbinoRhino; 07-21-2017 at 02:28 AM.

  10. #20
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    256

    Default

    if ( available _amount(it) > 0 ) {} <---- Items that are ' available ' to you according to the game state and your autoSatisfy settings.
    Originally Posted by AlbinoRhino View Post
    Here's what i ended up tryng:

    PHP Code:
    void main()
    {
        foreach 
    it in $items[
    8-ball,
    3-ball
    2-ball
    anticheese,
    talisman of baio]
        {
            if (
    available_amount(it) >= || storage_amount(it) >=)
        {
        print (
    "You have " available_amount(it) + " " +it" on hand, and " storage_amount(it) + " in storage""green");    }
            
    } } 
    and here's the printout:
    You have 0 8-ball on hand, and 33 in storage
    You have 0 3-ball on hand, and 6 in storage
    You have 0 2-ball on hand, and 11 in storage
    You have 1 anticheese on hand, and 21 in storage

    This is perfect for me right now! This is exactly what I'm looking for the script to do.

    The available_amount(it) looks at what I have in my inventory. I'm not sure what setting to change, but it's ok. I'm happy with the script the way it will come out.
    Last edited by Pazleysox; 07-21-2017 at 12:26 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
  •