0 votes
by (210 points)
closed by
So I'm trying to make a choice for my players that allows them to pick multiple things- say an inventory-type thing. Minor spoiler, I'm sort of making an adult game. I already know how to make buttons but I don't know how to get rid of just ONE. What I want is, when you clikc on one button, that button is renoved but all other buttons reamain. For instance, something like....

<<button "remove shirt">>
<<set $topless to 1>>
<</button>>

<<button "remove pants">>
<<set $pantsless to 1>>
<</button>>

<<button "remove underwear">>
<<if $topless is 1 and $bottomless is 1, set $naked to 1>>
<<else set $breezy to 1>>
<</if>>
<</button>>

Now my problem is if I leave it like that, the buttons still remain, even if they're topless- of course I don't want that. And using <<remove button>> removes them all for that page. Every node considered "button" is... removed. Any way to make JUST that specific button be removed..?

I am using sugarcube if it matters
closed with the note: Code works now, question answered

1 Answer

+1 vote
by (159k points)
edited by

Please use the "Insert Code Snippet" toolbar button when adding a code example to your comments.

There are a number of issues with your existing example:

1. Your <<if>> and <<else>> macro calles are malformed, the set calls should be within the macro's body.

<<if $topless is 1 and $bottomless is 1>>
	<<set $naked to 1>>
<<else>>
	<<set $breezy to 1>>
<</if>>

2. You apear to be using numbers to indicate a Boolean state.

If a variable can only be one of two possible values (yes/no, on/off, true/false, ect..) then it is considered a Boolean data type, which means you should be using the true and false literal values instead.

<<set $topless to false>>
or
<<set $topless to true>>

... and your <<if>> macro would then look like the following.

<<if $topless and $bottomless>>
	<<set $naked to true>>
<<else>>
	<<set $breezy to true>>
<</if>>

NOTE: You should initial all your story variables before you use them, and the ideal place to do this is within your project's StoryInit special passage.

<<set $topless to false>>
<<set $pantsless to false>>
<<set $bottomless to false>>
<<set $naked to false>>
<<set $breezy to false>>


If you were using <<link>> macros then I would suggest replacing the ones in your example with  <<linkreplace>> macros, but you are using the <<button>> macro and there isn't a 'replace' variation of that so you will need to do it the long way.

EDIT: Added two extra examples: one using Boolean variables; and one using Booleans and the <<remove>> macro.

The following uses Custom Style markup to define three IDed areas on the page, and then uses the <<replace>> macro to clear out each of these areas as needed.

@@#remove-shirt;<<nobr>>
<<button "remove shirt">>
	<<set $topless to 1>>
	<<replace "#remove-shirt">><</replace>>
<</button>>
<</nobr>>@@

@@#remove-pants;<<nobr>>
<<button "remove pants">>
	<<set $pantsless to 1>>
	<<replace "#remove-pants">><</replace>>
<</button>>
<</nobr>>@@

@@#remove-underwear;<<nobr>>
<<button "remove underwear">>
	<<if $topless is 1 and $bottomless is 1>>
		<<set $naked to 1>>
	<<else>>
		<<set $breezy to 1>>
	<</if>>
	<<replace "#remove-underwear">><</replace>>
<</button>>
<</nobr>>@@

The following example is the same as above except it uses Boolean based variables instead of Number based variables.

@@#remove-shirt;<<nobr>>
<<button "remove shirt">>
	<<set $topless to true>>
	<<replace "#remove-shirt">><</replace>>
<</button>>
<</nobr>>@@

@@#remove-pants;<<nobr>>
<<button "remove pants">>
	<<set $pantsless to true>>
	<<replace "#remove-pants">><</replace>>
<</button>>
<</nobr>>@@

@@#remove-underwear;<<nobr>>
<<button "remove underwear">>
	<<if $topless and $bottomless>>
		<<set $naked to true>>
	<<else>>
		<<set $breezy to true>>
	<</if>>
	<<replace "#remove-underwear">><</replace>>
<</button>>
<</nobr>>@@

The following example is the same as above except it uses the <<remove>> macro instead of the <<replace>> macro.

@@#remove-shirt;<<nobr>>
<<button "remove shirt">>
	<<set $topless to true>>
	<<remove "#remove-shirt">>
<</button>>
<</nobr>>@@

@@#remove-pants;<<nobr>>
<<button "remove pants">>
	<<set $pantsless to true>>
	<<remove "#remove-pants">>
<</button>>
<</nobr>>@@

@@#remove-underwear;<<nobr>>
<<button "remove underwear">>
	<<if $topless and $bottomless>>
		<<set $naked to true>>
	<<else>>
		<<set $breezy to true>>
	<</if>>
	<<remove "#remove-underwear">>
<</button>>
<</nobr>>@@

 

by (210 points)
edited by
A lot of this is very confusing to me. Please keep in nmind I'm very new to this stuff.

What is this "nobr" for? Are the double @ signs necessary? Is the semicolon? How does all of this work, and why? What's the difference between simply using <<button "___">> and using this #"__" method? Finally.. why have I only just now heard of all of this extra stuff with the @ and # signs?

-----------
Update: I still do want information about this, but now I'm just curious why it doesn't work. I set all the necessary variables to 0 in my "loading screen" before the title, then went in and added all that code above, with a few minor changes form the word "shirt" to certain specifics like "bikini top". I don't think the name matters. The apparent problem is when I go to replace, copying the code near-perfectly, it says it isn't able to because there's no element with the aforemetioned title. Did I do something wrong or does it not work with Sugarcube 2.0?
by (44.7k points)
edited by

First, you'll want to bookmark this link to the SugarCube documentation and probably have that page open while you work on your code.

Next, the <<nobr>> macro makes it so that all content within that macro will display as if it's all on the same line, unless you use a <br> element to force a line break.  This makes it easier to format your code in a more readable way when you're working on it.

Yes, the double @ signs and the semicolons are necessary, because they're needed to set a custom style for a chunk of code and/or text, which the <<replace>> macro uses to tell what section of content to replace.  (Though you could just do <<remove "#remove-shirt">> instead of <<replace "#remove-shirt">><</replace>>, since the <<remove>> macro is a better fit for what you need here.)

If it helps clear things up, doing this:

@@#idname;Content@@

is the same as doing this:

<span id="idname">Content</span>

Also, in CSS you represent an HTML element's ID by using "#" and an element's class by using "." before the ID or class name, respectively.  So that's where the "#" comes from; it refers to the <span> element's id name.

 

"What's the difference between simply using <<button "___">> and using this #"__" method?"

The difference is that this causes the button to disappear after you click it, which is what you wanted.

 

"I don't think the name matters."

Depending on what names you changed, it can very much matter.  The name in this part:

@@#remove-pants;

must match the name in this part:

<<remove "#remove-pants">>

otherwise it won't work.

 

"Did I do something wrong or does it not work with Sugarcube 2.0?"

If you did everything right, it should work fine with SugarCube 2, so you probably didn't do something right.  It sounds like you have mismatched element IDs, as explained in the answer just above this one.

 

Hopefully that clears things up.  If not, you'll need to post an example of the code which isn't working so we can see what's wrong with it.

by (210 points)

Below is a copy of the code I have before the game. Just one of many choices I want the player to have.

@@#furry-kink;<<nobr>>
<<button "I'm a furry">>
	<<set $furry to 1>>
	<<remove "#furry-kink">><</replace>>
<</button>>
<</nobr>>@@

@@#bondage-kink;<<nobr>>
<<button "I like to be tied up">>
	<<set $bondage to 1>>
	<<remove "#bondage-kink">><</replace>>
<</button>>
<</nobr>>@@

@@#nudity-kink;<<nobr>>
<<button "I love to be/see people naked">>
	<<set $nudity to 1>>
	<<remove "#nudity-kink">><</replace>>
<</button>>
<</nobr>>@@

Even with the above, it seems to not work... I have a few images of the error code but unsure where I can post tose. Did I somehow copy someting down wrong?

by (44.7k points)

You're mixing the <<remove>> and <<replace>> macros together.

Instead of:

<<remove "#furry-kink">><</replace>>

it should just be:

<<remove "#furry-kink">>

once you fix that then it should work fine.

If not, you might want to make sure you have the latest version of SugarCube (currently v2.28.2; installation instructions here) and see if that solves the problem.

Hope that helps!  :-)

by (210 points)
Well, my only problem downloading is as this is not my own computer, and thus I am forced to use the version they haveonline. Unless somehow that download is simply like an update file for the browser? If it's absolutely mandatory to get the download to make this work, then I may have to work around this with links instead- hey, whatever gets the dang code to work!

Thank you however for all your kind, hard work. I greatly appreciate and may even let you play a demo before anyone else~ the least I could do for someoen helping to make this a reality.
by (44.7k points)

I just tested the code with the online version of Twine and it worked just fine.

I just created a new story, made sure the story format was set to SugarCube, pasted this code in the passage:

@@#furry-kink;<<nobr>>
<<button "I'm a furry">>
	<<set $furry to 1>>
	<<remove "#furry-kink">>
<</button>>
<</nobr>>@@

and then hit the "play" button.  It showed me the button, and when I clicked on it the button was removed and the variable was set.

Try making another story and doing just those steps to see if it works.  If it works, then something in your other story is causing the problem.  If it doesn't work, then post the error message so maybe we can figure out what's going wrong.

by (210 points)
Code appears to be working now. Seems the problem was I had the format to sugarcube 1.5, not 2.2.1. I did try just the button in a new story and, as expected, it didn't do anything because there was no $furry variable. But after making a <<set $furry to 0>>, thatworked as well. Seems the button code and all that is something that was introduced in the 2.0 and on versions of S.C.

TYVM for all your help so far, HiEv, and I will be sure to call on you again if ever I need more help~
...