Select Next Empty Inventory Slot?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hey,
    I've made 10 counters, each going up to 1. I want it so that when you collect a resource (clicking on it) it picks the next empty slot to the left and creates an icon with a counter saying how much of that resource is in that slot. When you pick up another of the same resource, it adds to the counter, while collecting a new resource picks the next slot.
    Is there a way to do this automatically?
    Thanks,
    TooTinyMan

  • You'll need to make this, and it's a bit complicated.

    you could do something like this:

    when you collect a new resource, add a character to represent it on an alterable string.
    f.ex "1" = wood, and "2" rock. so when you pick a wood set alterable string A to:
    alterable string A + "1".
    then add 1 to alterable value (by index), at index: Find(Alterable String A( "Active" ), "1", 0)

    this finds where in the string "1" is located on the string, which is the slot number.
    and the amount of each resource is stored on each alterable value.

    to know if the resource has been added compare if Find(Alterable String A( "Active" ), "1", 0) is equal to -1, that means it's not there.
    So if it's equal to -1 then add "1" to alterable string A (then the number to value at index), otherwise skip the character and just add 1 to alterable value at index, since you already added that kind of resource.

    f.ex if you collect rock "2", then wood "1", then water "3", and another water "3".
    your string would be "213"
    and the alterable values would be 1,1,2.

    the reason to put numbers in a string like this, is so you can extract the number and use that to display the icon for your resource. f.ex by just setting the animation direction. so direction 1 = wood, and direction 2 = rock.

    now to update the display, run a fastloop len(Alterable String A( "Active" )) times, then the loop runs for each different kind of resource collected, which is the number of characters in the string, lets call this loop "x".
    on this loop, create the icons by setting the direction to val(Mid$( Alterable String A( "Active" ), LoopIndex("x"), 1))
    this picks out each character one by one and sets the icon correctly.

    now you just need to set the number, which is AltValN( "Active", LoopIndex("x") ) <- alterable value at index


    done, the only hard part now is if you need to remove a resource when it's spent down to 0, but it's managable! i'll explain how if you managed to follow what i've said so far and want to add that.

    the amount of each resource, f.ex rock, is: AltValN( "Active", Find(Alterable String A( "Active" ), "2", 0) ) just replace "2" with the icon number for each resource.

    if you want to spend a resource, you'll need to subtract from alterable value by expression, using the same: Find(Alterable String A( "Active" ), "2", 0)

    the above example supports 10 different kinds of resources, and any number of slots, sorry if this is way above your head, but to make it exactly like you want, with the flexible slots, it needs to be almost this complicated.

    Please login to see this link. =)

    Edited 4 times, last by SoftWarewolf (August 28, 2016 at 4:07 PM).

  • Alright, thanks!
    I'll try this, and if I can't get it to work I'll try to figure out the Inventory Object/Extension. The only reason I didn't start with the Inventory Extension is because it's confusing and there aren't any tutorials.
    Thanks again!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!