Howdy, Stranger!

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

Sugarcube: Append text to rpg system combat log

I've been using this really good combat system for an rpg that I'm working on. In the log passage here, once you click on a different action, the previous text disappears and is replaced.

Is there a way to modify this system to retain all the text from all the actions the player uses? (New text resulting from previous actions simply get appended to the log)

This system uses Harlowe, but I was hoping to see if the modification I want is possible in Sugarcube (already converted the current system to Sugarcube on my end).

Thank you!

Comments

  • edited October 2016
    notes:
    a. You didn't supply an example of your converted version of that Harlowe based code, so I am going to assume that your version looks and works the same as mine does.

    b. You don't state which version of SugarCube you are using, so I will assume it is the one that comes with Twine 2.x

    You can use an array to accumulated each action generated by the existing code in the Log passage and then display the contents of that array as the log text.

    1. Initialise the $actions array in the Ready passage, you should add something like the following just before the <<goto>> macro.
    <<set $actions to []>>
    

    2. Add the current action to the $actions array the display its contents.
    The following code replaces the current contents of the Log passage, you should also add a nobr passage tag to the passage.
    <<silently>>
    <<if $log is "you">>
    	<<set $actions.push("It is your turn.")>>
    <<elseif $log is "atk">>
    	<<set $actions.push("You use '" + $atk + "' on the " + $ename + ", dealing " + $atkdmg + " damage.")>>
    <<elseif $log is "enemy">>
    	<<set $actions.push("The " + $ename + " uses '" + $eatkname + "' on you, dealing " + $eatk + " damage.")>>
    <</if>>
    <</silently>>
    <div id="log"><<print $actions.join("\n")>></div>
    
  • Ah yes, the Sugarcube and Twine are all the current updated versions.

    And this works like a charm, thank you very much!
Sign In or Register to comment.