"if" statements

PenPlush
10 Feb 2023, 14:51

I am working on a game and I need the game to write text similar to this.

"The year is 2099, 65 years after the end of the world. you're name is " + (player.alias) + "You are sided with " + (player.faction)

that would work fine on its own as an expression however it isn't quite what I need. I'm hoping to have the game print a specific message depending on which faction the player decides to start the game with.

Ex:
-If the player sides with faction 1: "You come from F1, a militaristic faction suffering from greed amongst it's ranks.
-If you side with faction 2: "You come from the faction known as F2, You and your brothers preach the word of the cultic church."

I hope this makes some kind of sense.


GeminiNeule
10 Feb 2023, 16:37

You can do this in several ways. Examples below both include the faction being a number (player.faction) as well as a string (player.factionname)

Within the text processor:
{if player.faction=1:You are sided with faction 1}{if player.faction=2:You are sided with faction 2}{if player.factionname=three:You are sided with faction 3}

Using a script with if:

msg ("<br/>If with number:")
if (player.faction=1) {
  msg ("Faction One (number)")
}
else if (player.faction=2) {
  msg ("Faction Two (number)")
}
else if (player.faction=3) {
  msg ("Faction Three (number)")
}
msg ("<br/>If with text:")
if (player.factionname="one") {
  msg ("Faction One (text)")
}
else if (player.factionname="two") {
  msg ("Faction Two (text)")
}
else if (player.factionname="three") {
  msg ("Faction Three (text)")
}

Or using a switch statement in a script:

msg ("<br/>Switch with number:")
switch (player.faction) {
  case (1) {
    msg ("Faction one (number)")
  }
  case (2) {
    msg ("Faction two (number)")
  }
  case (3) {
    msg ("Faction three (number)")
  }
}
msg ("<br/>Switch with text:")
switch (player.factionname) {
  case ("one") {
    msg ("Faction one (text)")
  }
  case ("two") {
    msg ("Faction two (text)")
  }
  case ("three") {
    msg ("Faction three (text)")
  }
}

Depending on how often this text is used, you could also store the description as an attribute, preferable to a faction object. If you are using the gamebook type: You can use a page as "faction object". Do something like this early on, for example in the setup script of your game.

faction_a.factionnumber = 1
faction_a.factionname = "one"
faction_a.factiondescription = "This is the description for faction 1"

When the player decides to join that faction:

player.factionobject = faction_a

Later on you would not need to have an if when giving out the faction description.

msg ("<br/>Skript accessing faction object<br/>")
localfaction = player.factionobject
msg (player.factionobject.factiondescription)
msg (localfaction.factiondescription)