Restricting Choices

So first, context. At the beginning of the game, the player chooses a class to play as. Further, i.e. a battle scene, I want to have some options be unavailable depending on the class they took. Say, the player chose Warrior, and thus the battle option of Burn them with a Firebolt would be restricted/unable to be chosen since Warriors can't cast spells. How do I implement this, or is it not possible?
As well, I am running Quest on my laptop, and it's a Gamebook option rather than the Textbook option.
Thanks for the help!


Personally I would add an attribute to the character object called characterClass(or whatever you prefer) and use a switch statement to display the available options.
I have not used quest for a gamebook, just text adventure but it's likely just a matter of using a switch.
I prefer twine for gamebooks.
Gamebooks are my UML, then I convert what I wrote into a text adventure. Try it.
Text adventure is way cooler IMO.


I suppose if you made different commands for each class, as well as different weapons and functions for the enemies, that would work. I use The Pixie's zombie code for my combat, and I have had success with replacing certain functions to fix grammar mistakes. It was hard, by I was successful.


Something like this?

switch (player.class) {
  case ("Warrior") {
    attacks = Split ("Cleave;Shield bash;Whirlwind;Charge", ";")
    ShowMenu ("", attacks, true) {
      switch (result) {
        case ("Cleave") {
          msg ("You cleave the fridge out of your enemy. Boomshakalak.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Shield bash") {
          msg ("You bash your shield into the face of your enemy.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Whirlwind") {
          msg ("Like a storm you come down upon the group of enemies. Boo-yah!")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Charge") {
          msg ("You charge your foo and yell GERONIMOOOOOOO!!!")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
      }
    }
  }
}




You still need to script:

  1. The other classes (I only made warrior)
  2. Everything else that needs to happen when you attack.
  3. Maybe change the msg since I just wrote nonsense.

Edit:
Put the code above in a function and call it whenever you type attack(or whatever verb you'll use).

If you're unsure as to where to put the other classes, check it in GUI mode. It should be logical to you where everything goes now that you have one class.
(If you already do know... nevermind :))

Also: This works if the player object has the class attribute set to string and "Warrior".


I am not sure how restricted you will be in Gamebook (and that may be an issue with some suggestions above). Personally I would do it as a text adventure, but with hyperlinks, because this will be complex and you ned the extra functionality.

As a modification to CheeseMyBaby's idea, I would give the player an attribute that lists the options, and set that up at character creation.

switch (player.class) {
  case ("Warrior") {
    player.attacks = Split ("Strike;Cleave;Shield bash;Charge")
  }
  case ("Wizard") {
    player.attacks = Split ("Strike;Fireball;Lightning bolt;Mana drain")
  }
  case ("Rogue") {
    player.attacks = Split ("Strike;Back attack;Charge")
  }
}

Then use that when giving the player options:

    ShowMenu ("Choose your attack", player.attacks, true) {
      switch (result) {
        case ("Strike") {
          msg ("You attack the guy with your mighty weapon.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Cleave") {
          msg ("You cleave the fridge out of your enemy. Boomshakalak.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Shield bash") {
          msg ("You bash your shield into the face of your enemy.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Charge") {
          msg ("You charge your foo and yell GERONIMOOOOOOO!!!")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
        case ("Fireball") {
          msg ("You shoot a ball of fire at your hapless foe and laugh as it is consumed in fire.")
          // SCRIPT DAMAGE, HEALTH and what not HERE
        }
       // etc.
      }
    }

You can even add extra attacks as the game progresses.

list add (player.attacks, "Divine retribution")

I don't see why everyone is making it so complex.
If you want the same options to be available in every battle, it makes sense to have a menu like shown above. But if it's just a case of restricting choices, you could do it with simple script-and-text pages.

In the page where they've chosen to be a warrior, I assume you have a script like:

player.class = "Warrior"

and then on the battle page, you would have something like:

if (player.class = "Warrior") {
  dictionary remove (this.options, "Burn them with a Firebolt")
}

or more likely:

if (not player.class = "Wizard") {
  dictionary remove (this.options, "Burn them with a Firebolt")
}

You can put as many options as you need in the script, and it will remove the named options from the current page.
That's probably the simplest way to do it if you want to just restrict the options, rather than creating a full combat system (which is the impression I got from your first post).


Snap. I missed the fact that it's a gamebook. I know nothing about those.


@MrA

I figured it actually would be less complicated that way. If there’s lots of classes and every class has 3-5 possible attacks there would be a whole lot of excluding later on.
I might be wrong. It’s been known to happen. Pretty much most of the time :)

Either way, I’m guessing it might help for the OP to be presented with more ways than one. I’ve always appreciated that personally.

@Pix
Sweet! Now I learned how to be more effective. Thanks!


Well, I've seen two ways of handling combat in (actual printed) gamebooks. One is that every combat situation has like "If you are a wizard, you may turn to page 393 to cast Word of Immolation on the goblin". In that case, the attacks aren't the same each time, so it's probably less work to have one if statement to disable it for each option on the page.

And the other is having an actual battle system; which could be done with a lot of use of ShowMenu, but would really be easier to implement as a text adventure that looks like a gamebook.

Actually, if you're doing this a lot, here's a third method. As a game-wide thing, you could have this as your game.roomenter script ("Script when entering page" in the game's "Script" tab):

if (HasAttribute (player.parent, "options") and not HasAttribute (player.parent, "alloptions")) {
  player.parent.alloptions = player.parent.options
}
if (HasAttribute (player.parent, "alloptions")) {
  options = NewStringDictionary()
  class = player.class
  foreach (key, player.parent.alloptions) {
    option = DictionaryItem (player.parent.alloptions, key)
    pos = IndexOf (option, "]")
    if (StartsWith (option, "[") and pos > 0) {
      classes = Mid (option, 2, pos - 2)
      option = Trim (Mid (option, pos + 1))
      if (ListContains (Split(classes), class)) {
        dictionary add (options, key, option)
      }
    }
    else {
      dictionary add (options, key, option)
    }
  }
  player.parent.options = options
}

So if there's a lot of options that depend on character class, but they're not the same in every battle, you can make them all normal gamebook pages. But enter the text for the link as [Barbarian;Knight] Smash the goblin with your battleaxe or [Wizard] Cast a nasty spell at the ogre. With that script in place, the links that the player isn't the right class for will automatically be hidden.


Sounds about right. Like I said, I missed the fact that it's a gamebook. I keep forgetting that choice even exists when starting a new project in Quest (since I've only started two and I've been working on them since March. Or May. I forget... that too).


Thank you all for the massive help! I am switching it to a text game rather than gamebook, because someone pointed out that it was easier. I also planned only 1 or 2 attacks per class, and 3 or 4 classes. So I hope to implement all these and finish up my game soon! Thanks again for the example code, I kinda suck at figuring out what I need to write lol


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums