Need dynamic death messages in a function (using parameters)

TiberianEuan
25 Aug 2021, 10:14Hi there!
A friend of mine and I are making a multiplayer game together.
We got the multiplayer aspect all sorted out, and are looking to make a game over for the puzzle game.
I decided to make the "GAME OVER" into a function, to save the need for creating tons of the same script.
However, my friend and I settled for dynamic "teasing text" on the death, and if a player dies from something in a category, the said text will tease them with something related.
Example:
One dies from excessive heat
Teaser text = "Ooh, it's hot in here."
Here's the placeholder code, looking to either get a full fix or a format to properly define the "If" conditions:
if (gameover(cause) = heat) {
PrintCentered ("\"Ooh, is it hot in here?\"")
}
else if (gameover(cause) = cold) {
PrintCentered ("\"Brrrr.. Getting a bit chilly around here.\"")
}
else if (gameover(cause) = spikes) {
PrintCentered ("Pro Tip: Don't get impaled.")
}
else if (gameover(cause) = bloodloss) {
PrintCentered ("\"u got red on u.\"")
PrintCentered ("\"y you not got red in you?\"")
PrintCentered ("\"y red escape from u?\"")
}
else if (gameover(cause) = bullets) {
PrintCentered ("Fun Fact: Bullets aren't a natural part of the human body, you might want to get that removed.")
}
else if (gameover(cause) = decapitation) {
PrintCentered ("\"Calm down, don't lose your head.\"")
PrintCentered ("(oh wait, you already did..)")
}
else if (gameover(cause) = pvp) {
PrintCentered ("\"There can be only one!\"")
}
else if (gameover(cause) = choking) {
PrintCentered ("\"Woah man, breathe.\"")
PrintCentered ("(what do you mean you can't?!)")
}
else if (gameover(cause) = hunger) {
PrintCentered ("\"Wait, what do you mean you starved to death in a puzzle game?\"")
}
else if (gameover(cause) = exhaustion) {
PrintCentered ("\"Crunching is bad. Don't do it.\"")
}
else if (gameover(cause) = karate) {
PrintCentered ("Hold on, one sec, i gotta find a ninja sound on the internet.")
PrintCentered ("Huh, no google results.")
PrintCentered ("Oh wait.")
}
else if (gameover(cause) = dividebyzero) {
PrintCentered ("Both players fell out of the world.")
}
else {
PrintCentered ("Somebody died!")
}```

TiberianEuan
25 Aug 2021, 10:18also, if you're wondering how we made multiplayer,
we made 2 characters, a command to swap control between the two, and a naming system.
basically player 1 inputs things to be done by the player one character called "One" by default.
player 1 tells player 2 to get ready to control
player 1 types "swap" and all commands after are done by player 2's character
player 2 controls player2, aka "Two"
player 2 tells 1 to be ready, and then uses the swap command
so on so forth
mrangel
26 Aug 2021, 00:34I'm not sure what those conditions are supposed to do.
if (gameover(cause) = heat) {
So… when it gets to this point, it calls the gameover
function, passing a loval variable or object named cause
to it, and tests if the result is an object named heat
.
If this is within the gameover function, it will keep on calling itself forever.
I assume that your function has a parameter called "cause".
If you just want to check this cause against different values, you could use something like:
if (cause = "heat") {
PrintCentered ("\"Ooh, is it hot in here?\"")
}
else if (cause = "cold") {
and so on.
Or, as you're comparing one value against many options, you could use the much more efficient "switch" statement:
switch (cause) {
case ("heat") {
PrintCentered ("\"Ooh, is it hot in here?\"")
}
case ("cold") {
PrintCentered ("\"Brrrr.. Getting a bit chilly around here.\"")
}
// etc etc, all your other cases
default {
PrintCentered ("Somebody died!")
}
}