Hello, I’m trying create a new game on Sugacube 2.0. I have run into the issue of creating NPS. Do I need to use the Set macro? Does code need to be on another passage? How do I link variables to set NPC?
NPCs are, in general, collections of parametres, so you have to use the <<set>> macro to define those parametres using variables. You’ll want to use objects to define multiple values for a single NPC. Example:
<<set $npc1 to {
name:"Kate",
age: 23,
}
>>
As for everything else – like where to define the NPCs (StoryInit or somewhere else), or how to change their assigned values during gameplay – it all depends on what you want to achieve. Are the NPCs supposed to be static, or do you want to have aspects that change (for example, friendship level with the player)? Do you want the same, predefined NPCs in every playthrough, or do you want to create them with some randomization? If you want randomization, does it take place only at the start of the playthrough (let’s say you want to randomize the names of the player character’s friends, which won’t change later during gameplay), or later (maybe you have an “area” in your game where the player is attacked by an enemy, and you want the enemy’s stats to be randomized each time the player visits the area to keep the encounter more interesting)?
Thank you for the suggestion. I am currently trying to make an open world type of game with a lot of narrative elements. So I need NPCs to not only have a clear schedule but also make sure that theyre own stats i.e friendship, romance changes according to the player interacting with them. Is there any way of doing that. Plus how do I change the stats of the main character, that is also visible on the side bar.
First, you should set the initial values for your character in the special passage named StoryInit. Something like this:
<<set $kate to {
name: "Kate",
friendship: 3,
}
>>
<<set $dylan to {
name: "Dylan",
friendship: 2,
}
>>
Then, you can print these values in your passages ($kate.friendship will print the current value of Kate’s friendship), and also change them. In the following example, clicking the link forwards the player to a passage called Next and also increases Kate’s friendship value by 1:
<<link [[Spend time with Kate|Next]]>><<set $kate.friendship += 1>><</link>>
You can also use if statements to test values associated with your NPCs:
<<if $kate.friendship >= 10>>
You and Kate are great friends!
<<else>>
You can still improve your friendship with Kate.
<</if>>
As for the player charactes stats, you can go about that in the same way – just create one more object for the player character in StoryInit and give it the values you want. And to have text visible in the side bar, you should put it in a special passage named StoryCaption.