Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

combined Macro Set code examples

How would I use <<replace>> or <<replacelink> in the sugarcube version Im using in conjunction with if statements inside that give you multiple options to be clicked and replaced instead of just down one path?

Comments

  • edited October 2016
    <<if $hullBreached>>
        <<if $wearingHardSuit>>
            <<display "That was close">>
        <<elseif $wearingSoftSuit>>
            <<display "Hole in suit">>
        <<else>>
            <<display "You die">>
        <</if>>
    <</if>>
    

    Heres my example
    <<if $utilitybill eq 1>>
    <<replacelink>>Wash off your face and all your make up.<<set $redlipstick to 0>> <<becomes>> <<if $shaved is true>>
    All clean and ready to get your face painted! <<elseif>> All clean with stubble on your face. <<endreplacelink>>
    <</if>>
    <</if>>
    


    How do I make this work?

    This uses macros for <replacelink> in javascript that I took .

    Does an else have to be followed by an elseif?
  • Heres my example
    <<if $utilitybill eq 1>>
    <<replacelink>>Wash off your face and all your make up.<<set $redlipstick to 0>> <<becomes>> <<if $shaved is true>>
    All clean and ready to get your face painted! <<elseif>> All clean with stubble on your face. <<endreplacelink>>
    <</if>>
    <</if>>
    
    Issues:
    • Your inner <<if>> is comparing a boolean value to one of the boolean literals. Don't do that.
    • Your inner <<if>> uses an <<elseif>> with no conditional. That should probably be an <<else>>.
    • You placed the closing tag of the inner <<if>> outside of its parent <<replacelink>>. It should be inside.

    Try something like the following: (using the line continuation mark for readability)
    <<if $utilitybill eq 1>>\
    <<replacelink>>\
    <<set $redlipstick to 0>>\
    Wash off your face and all your make up.\
    <<becomes>>\
    <<if $shaved>>\
    All clean and ready to get your face painted!\
    <<else>>\
    All clean with stubble on your face.\
    <</if>>\
    <</replacelink>>\
    <</if>>
    

    Does an else have to be followed by an elseif?
    If specified, there should only ever be one <<else>> per <<if>> and it should always be the last clause. So, no, it should never be followed by an <<elseif>>.

    The order must be like the following:
    1. Mandatory opening <<if condition>>.
    2. Optional <<elseif condition>>. As many as are necessary.
    3. Optional <<else>>. One only.
    4. Mandatory closing <</if>>.
  • Thank you.

    I noticed you just wrote
    if $shaved
    
    . This needs more to it to work right? Like a false or true or does it automatically check if its true if you omit a condition to meet?
  • edited October 2016
    What is the first issue I listed in my previous post?

    You do not need to compare a boolean value to either of the literals. Conditional expressions ultimately simply to a boolean, so if your conditional expression consists of a boolean value, then that's all you need.

    For example:
    <<if $shaved>> is shaved …
    
    <<if not $shaved>> is not shaved …
    
  • eplacelink-macro-set/README.html So I know the replacelink macro set for sugarcube was done (by you?) but were the <timedreplace> ever coded over to sugarcube as well?

    http://www.glorioustrainwrecks.com/node/5029
  • also i couldnt get variables like $day/month/time to show up as their string counterparts? or string values like friday,june,12:00 until I used <<display storyinit>> in a starting passage, named 'start' just in case.

    "SugarCube supports a special passage named StoryInit, which is where the creator suggests you place your variable initialization." I always thought it was a requirement. Here it was giving me trouble until I think <<display storyinit>> fixed it? Any ideas why it wasnt working? $day would just show up as $day in the side bar.
  • […] were the <timedreplace> ever coded over to sugarcube as well?
    At the top of the README is a link to the original macro set, which contains the information you seek—i.e. it lists every macro included in the set. If you'd taken a look you'd have seen that, yes, the <<timedreplace>> macro is included.

    also i couldnt get variables like $day/month/time to show up as their string counterparts? or string values like friday,june,12:00 until I used <<display storyinit>> in a starting passage, named 'start' just in case.

    "SugarCube supports a special passage named StoryInit, which is where the creator suggests you place your variable initialization." I always thought it was a requirement. Here it was giving me trouble until I think <<display storyinit>> fixed it? Any ideas why it wasnt working? $day would just show up as $day in the side bar.
    All special passage and tag names are case sensitive—i.e. StoryInit and storyinit are not the same passage. Spell it correctly, StoryInit, and it will work.

    That said, it's unclear to me whether you're attempting to print things from the StoryInit special passage. If you are, stop. Some special passages do not generate output—i.e. they're silent. StoryInit, in particular, is for initialization purposes, so it is one of the silent ones.

    If you wanted to print something within your starting passage that you initialized within StoryInit, then that's what you'd do. For example, setting up a variable in StoryInit:
    <<set $name to "World">>
    
    And then printing it in your starting passage, UI bar, or wherever:
    Hello, $name.
    
  • Oh, so it wasn't the <<display StoryInit>> that fixed why my UI bar wasn't showing the right calendar variables, but because I didn't know storyinit passage name was case sensitive. I saw another user have <<display StoryInit>> in his code and thought thats what I was missing. I guess theres no reason to ever do this as it can be totally avoided.
  • SugarCube's special names documentation does mention that the names are case sensitive.

    Also, as a general rule, most things are case sensitive, so unless something is specifically mentioned to be case insensitive, it's probably wisest to assume that it's not.
  • Do you know why I can't have <<becomes>> macro inside my if/else statement without it breaking?
  • edited October 2016
    Code example of what you're trying?
  • <<replacelink>>
    You see a door way.
     <<becomes>>
    You walk up to the door way.
    <<if $door == 1>> 
    
    You begin turning the knob <<becomes>> to find an empty room.
    
    
     <<else>>
      
    The door is locked <<becomes>> you turn back the other way.
    
     <</if>>
    
     <<becomes>>
     You leave for now.
    
    <</replacelink>>
    
    
  • edited October 2016
    Your description was a little backwards. The problem you have there is that the <<if>> is being broken by the <<becomes>>, not the other way around.

    The reason is because you may not interleave separate macro invocations, which is what you're attempting to do there. Basically, the <<replacelink>> macro is processed first, meaning that its <<becomes>> are chopping the <<if>> into three separate unrelated pieces, thus the error. What you need to do is to have two separate <<if>> invocations on either side of a <<becomes>>.

    Beyond that, the phrasing is currently a little awkward. I'd suggest a bit of a rewrite to eliminate one of the two <<if>> invocations you'd actually need with your current phrasing.

    I'd suggest something like the following:
    <<replacelink>>\
    You see a doorway.
    <<becomes>>\
    You walk up to the door and begin turning the knob.
    <<becomes>>\
    Only to find <<if $door eq 1>>an empty room.<<else>>that it's locked.<</if>>
    <<becomes>>\
    You leave for now.
    <</replacelink>>
    
  • Yes but can you show me how to use the replace link becomes macro in the if tag ?
  • edited October 2016
    Yes but can you show me how to use the replace link becomes macro in the if tag ?
    I just explained that you cannot do that and why you cannot. Here it is again:
    The reason is because you may not interleave separate macro invocations, which is what you're attempting to do there. Basically, the <<replacelink>> macro is processed first, meaning that its <<becomes>> are chopping the <<if>> into three separate unrelated pieces, thus the error. What you need to do is to have two separate <<if>> invocations on either side of a <<becomes>>.
    The <<becomes>> tags here belongs to the <<replacelink>> macro. You cannot place them within another macro or they'll chop that macro's invocation into pieces when the <<replacelink>> is processed and an error will result.

    EDIT: In more detail. When <<replacelink>> is processed, its contents are cut into chunks based on the <<becomes>> tags. Each one is a separate entity which is evaluated separately when you click on its link. For example, here's the first chunk:
    You see a door way.
    
    Second chunk:
    You walk up to the door way.
    <<if $door == 1>> 
    
    You begin turning the knob
    
    Third chunk:
    to find an empty room.
    
    
     <<else>>
      
    The door is locked
    
    Fourth chunk:
    you turn back the other way.
    
     <</if>>
    
    
    Fifth chunk:
     You leave for now.
    
    
    Hopefully, that will help you visualize why you cannot embed <<becomes>> tags within the <<if>> macro. When the the second chunk is evaluated, it only contains part of the <<if>> macro, which then throws an error because it's incomplete.
  • Got it. Is there a good resource that explains the difference between widgets and macros? Are widgets just custom made macros?
  • edited October 2016
    Taking these out of order.

    Are widgets just custom made macros?
    Basically, yes.

    Is there a good resource that explains the difference between widgets and macros?
    Not really. I suppose reading documentation of both the <<widget>> macro and the Macro API might do that.

    The cliff notes version is thus: The differences between API macros and Widget macros are minor—the <<widget>> macro actually uses the Macro API to create the widget you invoke. The most significant differences are:
    1. Widgets use other macros and markup as their code, while API macros are JavaScript.
    2. Widgets cannot be container/non-void macros—i.e. you can do <<foo …>>, but not <<foo>>…<</foo>> with a widget.
  • Got it. Can you put click macro in timed replace macro? I'd like click able links to dissapear if not clicked on time

  • Yes, provided you are not trying to interleave the two macros and their tags again—as is the case with virtually all macros, though some combinations don't make a lot of sense.

    For example:
    <<timedreplace 2s>><<click "A">>…<</click>>.<<becomes>>B.<</timedreplace>>
    
  • Can you put an if macro inside of a click macro?
  • Barring using the <<display ifcodeinthispassage>> work around?
  • Can you put an if macro inside of a click macro?
    Yes. Though, depending on what you're attempting to do, it may not be all you need, since <<click>> discards output. If you simply need it for logic within the <<click>>, then you're golden. If you also wanted output from it, then you'll also need to use one of the DOM macros and a target.

    As I've said before, you may place virtually any macro within a container/non-void macro—those with a closing tag—even other container/non-void macros, as long as you do not attempt to interleave their tags. Though, again, some combinations won't make a lot of sense—e.g. putting a macro which generates output, like <<print>>, within <<silently>>, which discards output.

    In other words, the following are okay:
    <<click …>>
    	<<if …>><</if>>
    <</click>>
    
    <<if …>>
    	<<click …>><</click>>
    <</if>>
    

    While the following are not okay: (you cannot interleave the tags of separate macros)
    <<click …>>
    	<<if …>>
    <</click>>
    	<</if>>
    
    <<if …>>
    	<<click …>>
    <</if>>
    	<</click>>
    
    <<if …>>
    	<<click …>>
    <<else>>
    	<</click>>
    <</if>>
    
Sign In or Register to comment.