inventory that describes each item whenever you press open backpack

edited April 2015 in Help! with 2.0
you undo the strap on your backpack viweing the contents in you backpack <<< like that i want kinda like a if stamens that if you have a sword or an apple you see them in your backpack...? I'm running sugercube and know some css but not a master... :P also receiving items would be like you reach your hands into you pockets in your ragtag grimy lether pants. you feel around and feel a compass /*this is where you recive compass in invintory

Comments

  • Don't you just want to write a passage with <<if>> macros and <<set>> $variables?

    I recommend viewing the SugarCube documentation to review variable functions.
  • sorry i don't understand can you use some example code?
  • Writing an inventory system is complex so you need to understand the underlying functions.

    http://www.motoslave.net/sugarcube/docs/macros.html

    Everything you need, including some examples, is on that page.
  • If it helps, I was able to get a VERY BASIC Inventory system going from one of the threads I found in the forums.

    It looks like this:
    <<set $inv = ["Dagger", "Shield", "Potion"] >>
    <<if $inv.length is 0>>You have nothing.
    <<else>>
    Your inventory contains:
    <<print $inv.join("\n")>>
    <<endif>>
    
    
    You decide to [[drop your potion]]
    
    ―> (new room)
    
    <<script>>
    // Removes an element from an array.
    // String value: the value to search and remove.
    // return: an array with the removed element; false otherwise.
    Array.prototype.remove = function(value) {
    var idx = this.indexOf(value);
    if (idx != -1) {
    return this.splice(idx, 1); // The second parameter is the number of elements to remove.
    }
    return false;
    }
    <</script>>
    
    It breaks on the ground and just in front of you, and you see....
    
    <<set $inv.remove('Potion')>>
    Your inventory now only contains:
    <<print $inv.join("\n")>>
    
    
    
    
    

    It isn't my original work... just one of the people on the forums. I did find it very helpful though.

    ―Sage
Sign In or Register to comment.