Adding/removing values from a Squiffy attribute

fvu109
05 Feb 2024, 14:54

I wonder if anyone might be able to help me with a bit of javascript!

In my current game, your character has a list of personality traits, set like this in a comma separated list:

@set traits_list = sad,hungry,cold

At various points of the game the player can take action to change these traits, for example cheering up a character

[[Take action]]:

You tell Bob a joke. He cheers up immediately!

[[Change trait]](Change trait,addTrait=happy,removeTrait=sad)

It's the next bit I'm struggling with - how to actually make those changes to {traits_list} based on those {addTrait} and {removeTrait} values, so that (in this case) {traits_list} would become hungry,cold,happy

Can anyone advise?


IFforClassroom
12 Feb 2024, 10:05

I'm lazy and I only use javascript if Squiffy code can't hack it. So the way I'd do it is simply

@set sad
@set hungry
@set cold

Bob is {if sad:sad}{else:happy}, {if hungry:hungry}{else:full}, and {if cold:cold}{else:warm}.
[[Take action]]

[[Take action]]:

You tell Bob a joke. He cheers up immediately! {@not sad} Now Bob is {if sad:sad}{else:happy}, {if hungry:hungry}{else:full}, and {if cold:cold}{else:warm}.

Is there something beyond your example that makes you want to have a single attribute called traits_list?


IFforClassroom
12 Feb 2024, 13:37

You can also use mrangel's unofficial update (Squiffy 5.1.4) to nest multiple attributes into one attribute. See if that covers what you hoped to do.