Howdy, Stranger!

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

A macro inside of a macro?

As the title suggests, I'm trying to figure out is I can make a macro inside of a macro. More specifically, I'm trying to make randomized ramifications to enter a village, a certain set of skills to be specific. I'm using Sugarcube, by the way

It should be noted that I am very new to coding. Any help would be much appreciated.

Comments

  • Are you asking if the code related to one custom macro can include a call to a second custom macro within it?
  • greyelf wrote: »
    Are you asking if the code related to one custom macro can include a call to a second custom macro within it?

    I believe so. The very rough outline I have so far is this:

    <<if $<<either "Fishing", "Hunting", "Foraging", "Field Medicine" or "Animal Husbandry'', "Farming", "Sewing", "Child Rearing">> is true>> Accepted

    <<elseif $<<either "Fishing", "Hunting", "Foraging", "Field Medicine" or "Animal Husbandry", "Farming", "Sewing", "Child Rearing">> is false>> Denied

    <</if>>

    This probably looks as rough as sand paper but, I guess it's better than nothing?
  • If I understand your example correctly:

    a. the "Fishing", "Hunting", "Foraging", "Field Medicine", etc are meant to be the names of different variables or properties in the story.

    b. each variable/property can be either true or false.

    c. you want to be able to test if one? / some? / all? of the variables/properties are equal to true (or false).
  • Yes, you are correct on all accounts and as for c, I would like to fort randomly generate one of the for and if the correct variable is chosen that would allow the player admittance. I guess you could say it's a bit of a lottery system.
  • edited September 2016
    Replies are out of order.
    Strangedog wrote: »
    I'm using Sugarcube, by the way
    Kudos for specifying which story format you're using—it's SugarCube, BTW. You really should also specify the version as well, however, as that does make a difference.

    For now, I'll assume that you're using SugarCube v1 (probably v1.0.34, if you're using Twine 2 v2.0.11).

    Strangedog wrote: »
    It should be noted that I am very new to coding. Any help would be much appreciated.
    I'd suggest starting by reading over SugarCube's documentation (docs for v1 or docs for v2).

    Strangedog wrote: »
    As the title suggests, I'm trying to figure out is I can make a macro inside of a macro.
    You cannot invoke a macro from within the argument list of another macro, no. That's not really an issue here, since, based on your description, that isn't really what you need to do.

    Strangedog wrote: »
    More specifically, I'm trying to make randomized ramifications to enter a village, a certain set of skills to be specific.
    You're probably looking for the either() story function, which you can find within SugarCube's documentation (see above).

    If these things will be story variables containing boolean values which you want to randomly select one one to test, then you probably want something like the following: (based on the random selection in your pseudo-example)
    <<if either(
    	$Fishing,
    	$Hunting,
    	$Foraging,
    	$FieldMedicine or $AnimalHusbandry,
    	$Farming,
    	$Sewing,
    	$ChildRearing
    )>>
    	Accepted
    <<else>>
    	Denied
    <</if>>
    
    The invocation of either() will randomly select the result of one of the given expressions and return its value. Based on the truthiness of that value, the <<if>> will execute either the 'Accepted' or 'Denied' code paths.

    Note: The $FieldMedicine and $AnimalHusbandry variables are ganged together via the logical-OR operator, since that's what your pseudo-example showed. If that was a mistake, then simply replace the logical-OR operator with a comma, just like the others.
  • I've altered the code a tad to fit my needs and I received an error:
    Error: <<if>>" bad conditional expression in <<if>> clause: Unexpected identifier.

    My code is:
    <<if $s-skill either (
    $Fishing, $Hunting, $Foraging, $Field Medicine
    )>>
    Accepted

    <<else if $d-skill either(
    $Animal Husbandry, $Farming, $Sewing, $Child Rearing
    )>>
    Accepted

    <<else>>
    Denied

    <</if>>

    By the way, thank you both for all of the help.
  • I've already pointed out why $s-skill isn't going to work in your other thread.


    Now I have to ask, what is the following supposed to be doing:
    <<if $s-skill either (
    $Fishing, $Hunting, $Foraging, $Field Medicine
    )>>
    
    Specifically, this bit:
    $s-skill either(…)
    
    A variable immediately followed by a function call, in a conditional expression. Are you trying to do an assignment there or what?


    Also, as noted in its documentation, the ELSE-IF tag of the <<if>> macro is spelled <<elseif>>—no space.
  • First thing has been noted and addressed, little slip up on my part, same for the last thing.

    As for what exactly I want it to be doing, I want to have the code select one of the four skills in each category, therefore giving the player a higher chance of winning the 'lottery". Honestly, I don't even know if what I'm trying to do is feasible.
  • It's totally feasible, and I'm not even certain exactly what you want yet. Basic logic is not hard problem, once we figure out what you want at least.

    May we assume that the categories and skills contained within are the following?
    • Category A: "Fishing", "Hunting", "Foraging", "Field Medicine"
    • Category B: "Animal Husbandry'', "Farming", "Sewing", "Child Rearing"
    If so, and if the skills have associated variables, then based on my understanding of what you claim to want.

    If the character must have both of the skills, randomly picked from the categories, then try something like the following:
    <<if
    	either($Fishing, $Hunting, $Foraging, $FieldMedicine) and
    	either($AnimalHusbandry, $Farming, $Sewing, $ChildRearing)
    >>
    	Accepted
    <<else>>
    	Denied
    <</if>>
    
    Basically, the character must have a randomly chosen skill from both category A and category B.

    Elsewise, if the character only needs one of the skills, randomly picked from the categories, then try something like the following:
    <<if
    	either($Fishing, $Hunting, $Foraging, $FieldMedicine) or
    	either($AnimalHusbandry, $Farming, $Sewing, $ChildRearing)
    >>
    	Accepted
    <<else>>
    	Denied
    <</if>>
    
    Basically, the character must have a randomly chosen skill from either category A or category B.

    The only difference between the two is the logical operator used to conjoin the two either() invocations—logical-AND for the former and logical-OR for the latter.
  • Perfect. Thank you!
Sign In or Register to comment.