0 votes
by (160 points)

Hello, I would like to start out by saying that I am completely new to Twine, downloaded the program last night, and everything has been straightforward so far. I set up a script with inventory macros designed for Sugarcube, and my item pickup was working perfectly well. The script is not the problem, it is the code, specifically the If statement set to check for $bagspace, I believe. When I click the link, all it does is refresh the page, the inventory is not changed like it should be, the if statement does not switch because I picked up the item, and the $bagspace does not go down. I have been trying on and off all day to figure this out. Here is my code:

<<if $playerInv.has('notebook'>>
    <<link 'Drop notebook.'>>
        <<drop '$playerInv' 'notebook'>>
        <<set $bagspace to $bagspace + 1>>
        <<goto "I didn't know what to do..."
    <</link>>
<<else>>
    <<link 'Take notebook.'>>
        <<if $bagspace gt 0>>
            <<pickup '$playerInv' 'notebook'>>
            <<goto "I didn't know what to do...">>
            <<set $bagspace to $bagspace - 1>>
        <<else>>
            Your inventory is full.
        <<endif>>
    <</link>>
<<endif>>

 

1 Answer

+1 vote
by (156k points)
selected by
 
Best answer

Please include the full version number of your story format when asking a question, as answers can vary based on that information.

Also if you ask a question that requires third-party macros (like the <<pickup>> and <<drop>> in your example) to run then please include either: a link to where ever you obtain those macros from; or a copy of those macro's source code. Doing that will help those testing your copy because we don't always know which third-party macros you are talking about.
eg. There are many different implementations of an Inventory system.

Assuming that your code example is an exact copy of the relevant code within your passage then it has a number of syntax errors in it.

1. The <<if $playerInv.has( line is missing a closing parenthesis at the end of the has() function.
2. The <<goto "I didn't line is missing the closing double greater-than character at the end of the <<goto>> macro.
3. The <<endif>>'s should be <</if>>

<<if $playerInv.has('notebook')>>
    <<link 'Drop notebook.'>>
        <<drop '$playerInv' 'notebook'>>
        <<set $bagspace to $bagspace + 1>>
        <<goto "I didn't know what to do...">>
    <</link>>
<<else>>
    <<link 'Take notebook.'>>
        <<if $bagspace gt 0>>
            <<pickup '$playerInv' 'notebook'>>
            <<goto "I didn't know what to do...">>
            <<set $bagspace to $bagspace - 1>>
        <<else>>
            Your inventory is full.
        <</if>>
    <</link>>
<</if>>

note: I had to assume that the calls to the <<pickup>> and <<drop>> macros are correct because I don't know which inventory system you are using.

by (160 points)
Thank you for you what ended up only being a proofread. Your corrections fixed the program and I have no idea how they missed me.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...