character creator/how to loop.[solved]

devilmaymoan
30 May 2019, 03:49

How can take a menu input and then ask if the player is sure of his/her selection?

Right now if the player select no, all is good but if they select no a second time on the same menu its over the menu don't show up again. here is what I have.

get input {
  player.alias = result
  msg ("Your name is " +player.alias+"?")
  Ask ("are you sure?") {
    if (result = True) {
      msg ("<br/><br/>")
      msg ("Hello " + player.alias +".")
      body = split("stud;twink;fat", ";")
      ShowMenu ("So next is your body type?", body, false) {
        switch (result) {
          case ("stud") {
            Ask ("Are you sure?") {
              if (result = True) {
                SetObjectFlagOn (player, "Body_stud")
                msg ("A yummy stud, I like it")
                wait {
                  MoveObject (player, Assets selection)
                }
              }
              else if (result = False) {
                msg ("Try again ...")
                body = split("stud;twink;fat", ";")
                ShowMenu ("So next is your body type?", body, false) {
                  switch (result) {
                    case ("stud") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_stud")
                          msg ("A yummy stud, I like it")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                        else if (result = False) {
                          body = split("stud;twink;fat", ";")
                        }
                      }
                    }
                    case ("twink") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_twink")
                          msg ("A cute little twink? who doesn't like those.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                    case ("fat") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_fat")
                          msg ("A bit overweight? no problem.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          case ("twink") {
            Ask ("Are you sure?") {
              if (result = True) {
                SetObjectFlagOn (player, "Body_twink")
                msg ("A cute little twink? who doesn't like those.")
                wait {
                  MoveObject (player, Assets selection)
                }
              }
              else if (result = False) {
                msg ("Try again ...")
                body = split("stud;twink;fat", ";")
                ShowMenu ("So next is your body type?", body, false) {
                  switch (result) {
                    case ("stud") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_stud")
                          msg ("A yummy stud, I like it")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                        else if (result = False) {
                          body = split("stud;twink;fat", ";")
                        }
                      }
                    }
                    case ("twink") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_twink")
                          msg ("A cute little twink? who doesn't like those.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                    case ("fat") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_fat")
                          msg ("A bit overweight? no problem.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          case ("fat") {
            Ask ("Are you sure?") {
              if (result = True) {
                SetObjectFlagOn (player, "Body_fat")
                msg ("A bit overweight? no problem.")
                wait {
                  MoveObject (player, Assets selection)
                }
              }
              else if (result = False) {
                msg ("Try again ...")
                body = split("stud;twink;fat", ";")
                ShowMenu ("So next is your body type?", body, false) {
                  switch (result) {
                    case ("stud") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_stud")
                          msg ("A yummy stud, I like it")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                        else if (result = False) {
                          body = split("stud;twink;fat", ";")
                        }
                      }
                    }
                    case ("twink") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_twink")
                          msg ("A cute little twink? who doesn't like those.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                    case ("fat") {
                      Ask ("Are you sure?") {
                        if (result = True) {
                          SetObjectFlagOn (player, "Body_fat")
                          msg ("A bit overweight? no problem.")
                          wait {
                            MoveObject (player, Assets selection)
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    else if (result = False) {
      msg ("Try again then ....")
      get input {
        player.alias = result
        msg ("Your name is " +player.alias+"?")
        Ask ("are you sure?") {
          if (result = True) {
            msg ("<br/><br/>")
            msg ("Hello " + player.alias +".")
            body = split("stud;twink;fat", ";")
            ShowMenu ("So next is your body type?", body, false) {
              switch (result) {
                case ("stud") {
                  Ask ("Are you sure?") {
                    if (result = True) {
                      SetObjectFlagOn (player, "Body_stud")
                      msg ("A yummy stud, I like it")
                      wait {
                        MoveObject (player, Assets selection)
                      }
                    }
                    else if (result = False) {
                      msg ("Try again ...")
                      body = split("stud;twink;fat", ";")
                      ShowMenu ("So next is your body type?", body, false) {
                        switch (result) {
                          case ("stud") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_stud")
                                msg ("A yummy stud, I like it")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                              else if (result = False) {
                                body = split("stud;twink;fat", ";")
                              }
                            }
                          }
                          case ("twink") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_twink")
                                msg ("A cute little twink? who doesn't like those.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                          case ("fat") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_fat")
                                msg ("A bit overweight? no problem.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
                case ("twink") {
                  Ask ("Are you sure?") {
                    if (result = True) {
                      SetObjectFlagOn (player, "Body_twink")
                      msg ("A cute little twink? who doesn't like those.")
                      wait {
                        MoveObject (player, Assets selection)
                      }
                    }
                    else if (result = False) {
                      msg ("Try again ...")
                      body = split("stud;twink;fat", ";")
                      ShowMenu ("So next is your body type?", body, false) {
                        switch (result) {
                          case ("stud") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_stud")
                                msg ("A yummy stud, I like it")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                              else if (result = False) {
                                body = split("stud;twink;fat", ";")
                              }
                            }
                          }
                          case ("twink") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_twink")
                                msg ("A cute little twink? who doesn't like those.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                          case ("fat") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_fat")
                                msg ("A bit overweight? no problem.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
                case ("fat") {
                  Ask ("Are you sure?") {
                    if (result = True) {
                      SetObjectFlagOn (player, "Body_fat")
                      msg ("A bit overweight? no problem.")
                      wait {
                        MoveObject (player, Assets selection)
                      }
                    }
                    else if (result = False) {
                      msg ("Try again ...")
                      body = split("stud;twink;fat", ";")
                      ShowMenu ("So next is your body type?", body, false) {
                        switch (result) {
                          case ("stud") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_stud")
                                msg ("A yummy stud, I like it")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                              else if (result = False) {
                                body = split("stud;twink;fat", ";")
                              }
                            }
                          }
                          case ("twink") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_twink")
                                msg ("A cute little twink? who doesn't like those.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                          case ("fat") {
                            Ask ("Are you sure?") {
                              if (result = True) {
                                SetObjectFlagOn (player, "Body_fat")
                                msg ("A bit overweight? no problem.")
                                wait {
                                  MoveObject (player, Assets selection)
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

I'm pretty sure there must be another way to do a loop to give give the player a chance to back up and try again in a loop lol.


hegemonkhan
30 May 2019, 06:58

examples of looping with an Object's Script Attribute and with a Function as well

(with a condition whether to loop or not, to prevent an infinite loop, as infinite loops crash quest, as resources/memory isn't infinite: programming/coding/scripting/etc, functions/scripts/etc store data, it all takes up resources/memory)

<game name="EXAMPLE">

  <attr name="start" type="script">

    invoke (example_object.example_looping_script_attribute)
    // or:
    // do (example_object, "example_looping_script_attribute")

    example_looping_function

  </attr>

</game>

<object name="example_object">

  <attr name="example_looping_script_attribute" type="script">
    ask ("loop?") {
      if (result) {
        invoke (example_object.example_looping_script_attribute)
        // or:
        // do (example_object, "example_looping_script_attribute")
      } else {
        msg ("You decided NOT to loop")
      }
    }
  </attr>

</object>

<function name="example_looping_function">
  ask ("loop?") {
    if (result) {
      example_looping_function
    } else {
      msg ("You decided NOT to loop")
    }
  }
</function>

The Pixie
30 May 2019, 07:02

If you find you are repeating code, then you should be using functions. Functions can call themselves, so what you want to do is have a function for each question, and if the player decides that is wrong, call the function again.

So we have a GetName function:

get input {
  player.alias = result
  msg ("Your name is " +player.alias+"?")
  Ask ("are you sure?") {
    if (result = True) {
      msg ("<br/><br/>")
      msg ("Hello " + player.alias +".")
      GetBodyType()
    }
    else {
      msg ("Try again then ....")
      GetName
    }
  }
}

And a GetBodyType function:

body = split("stud;twink;fat", ";")
ShowMenu ("So next is your body type?", body, false) {
  switch (result) {
    case ("stud") {
      Ask ("Are you sure?") {
        if (result) {
          SetObjectFlagOn (player, "Body_stud")
          msg ("A yummy stud, I like it")
          wait {
            MoveObject (player, Assets selection)
          }
        }
        else {
          msg ("Try again ...")
          BodyType()
        }
      }
    }
    case ("twink") {
      Ask ("Are you sure?") {
        if (result) {
          SetObjectFlagOn (player, "Body_twink")
          msg ("A cute little twink? Who doesn't like those.")
          wait {
            MoveObject (player, Assets selection)
          }
        }
        else {
          msg ("Try again ...")
          BodyType()
        }
      }
    }
    case ("fat") {
      Ask ("Are you sure?") {
        if (result) {
          SetObjectFlagOn (player, "Body_fat")
          msg ("A bit overweight? No problem.")
          wait {
            MoveObject (player, Assets selection)
          }
        }
        else {
          msg ("Try again ...")
          BodyType()
        }
      }
    }
  }
}

By the way result is either true or false; you do not need to compare it to true and you can be sure if it is not true then it is faslse, so in if/else, you it like this:

if (result) {
  // ... stuff...
} else {
  // ... other stuff...
}

devilmaymoan
30 May 2019, 20:17

Thanks a lot Pixie :)
I knew I was missing something lol.

problem solved


mrangel
31 May 2019, 17:25

An alternative, in case you find it useful:
I always found this method a bit clunky. My preferred alternative would be to put the questions in a turnscript, that looks something like:

(pseudocode)

if (not HasAttribute (player, "attribute1")) {
  ShowMenu ("Question 1", some bunch of options) {
    player.attribute1 = result
    msg ("Your attribute1 is now "+result)
  }
}

else if (not HasAttribute (player, "attribute2")) {
  ShowMenu ("Question 2", some bunch of options) {
    player.attribute2 = result
    msg ("Your attribute2 is now "+result)
  }
}

else if (not HasAttribute (player, "attribute3")) {
  ShowMenu ("Question 3", some bunch of options) {
    player.attribute3 = result
    msg ("Your attribute3 is now "+result)
  }
}

else {
  // all the attributes are set, so we can stop asking questions
  this.enabled = false
  // maybe move the player to the actual first room or something
}

You can include as many questions as you want, and even allow the player to go back and change their answers (by setting a previously-set attribute to null). The turnscript just makes sure that the player keeps on getting asked the first question they haven't answered yet.