get input {
switch(LCase(result) ) {
case("one", "two", "three"){
//stuff happens
}
default {
//stuff doesn't happen
}
}
}
The Pixie wrote:"TinFoilMkIV"
...
Also the 'Lcase()' function helps to deal with capitalization issues, ...
Some of them. You also need to capitalise LCase right!
//object 'combat', script attribute 'main'
msg ("You are in combat")
msg("")
msg("What would you like to do?")
get input {
switch (LCase(result)){
case("attack"){...}
case("hit it really hard"){...}
case("flee!"){...}
case("wait"){...}
default {
msg ("invalid choice")
wait{
ClearScreen
do (combat, "main")
}
}
}
default {
do (combat, "main")
}
//let's say player mispells choice
default {
msg(“What was that? Can you choose your response again, please?”)
do (get input, "switch")
}
}
}
//let's say player mispells choice
default {
msg(“What was that? Can you choose your response again, please?”)
do (get input, "switch")
}
get input {
ListContains(Split("sexy;sympathy;sarcastic;snoopy;serious",";")(LCase(result)) {
switch(LCase(result)) {
case(“Snarky”) {
msg(“”)
player.snarky = player.snarky + 1
}
case(“Sympathy”)
msg(“”)
player.sympathy = player.sympathy + 1
}
case(“Sarcastic”)
msg(“”)
player.sarcastic = player.sarcastic + 1
}
case(“Snoopy”)
msg(“”)
player.snoopy = player.snoopy + 1
}
case(“Serious”)
msg(“”)
player.serious = player.serious + 1
}
if (LCase(result) = "snarky"){
msg(“”)
player.snarky = player.snarky + 1
}
else if (LCase(result) = "sympathy"){
msg(“”)
player.sympathy = player.sympathy + 1
}
else if (LCase(result) = "etc"){...}
//let's say player mispells choice
default {
msg(“What was that? Can you choose your response again, please?”)
do (get input, "switch")
}
you're close, but you're using 'do' incorrectly there. The first parameter needs to be an object, and the second, the string, is the name of the attribute script to run. It's a lot like how 'player.serious' is a two part reference, the object name, and then the attribute within it you want to look at. The 'do' needs to first know the object, and then the name of the attribute, and the rest is up to the script you have stored in that attribute.
set (Object_name, "Attribute_name", Attribute_Value)
<game name="blah">
<start type="script">
do (creation, "character_creation")
</start>
</game>
<object name="creation">
<attr name="character_creation" type="script">
msg ("What is your name?")
get input {
player.alias = result
switch (player.alias) {
case ("HK") {
msg ("Your name is HK")
}
case ("Neonayon") {
msg ("Your name is Neonayon")
}
}
}
</attr>
</object>
HegemonKhan wrote:@ Tin:
how else or what else can 'do' be used for? I didn't know it could be used for other stuff besides activating~invoking a Script Attribute. Learned something new, laughs.
("")
get input {
switch (LCase(result)) {
case ("option1") {
msg ("You chose option1, clearing screen and restarting loop")
wait {
ClearScreen
do (control, "SwitchLoop")
}
}
case ("option2") {
msg ("You chose option2, restarting loop without screen clear or wait")
msg ("")
do (control, "SwitchLoop")
}
default {
msg ("invalid choice, please try again...")
msg ("(this is the default for the switch)")
msg ("")
wait {
do (control, "SwitchLoop")
}
}
}
}
<object name="control">
<attr name="SwitchLoop" type="script">
// possibly your scripts (depends on what your scripts are in whether they go inside of the 'while' loop block or outside of it)
flag = false
while (!flag)
// possibly your scripts (depends on what your scripts are in whether they go inside of the 'while' loop block or outside of it)
// your 'switch' block
// your 'cases' of the 'switch' block
// optional: the 'switch' default response
// put in this script line, flag = true, for when you want to end the while loop's 'looping' and continue on with the game, into (depends) whatever 'cases' and~or the 'default response. Based on what you've posted, it sounds like if any of the cases happen, you want to end the looping and move on, so you EACH~ALL of your cases, you'll need this script line in them: flag = true // or via GUI~Editor: set variable flag = [expression] true
</attr>
</object>
while(flag){
get input {
//do stuff
//turn flag off when a case that ends the loop happens
}
//this part of the script will still run while waiting on the get input
//...
//you now get an error because the loop will try to constantly re-run your get input while the first one is still waiting.
}
flag = false
while (!flag) {
msg ("xxx")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
flag = true
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
flag = true
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
flag = true
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
flag = true
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a veryy serious tone.<br/>")
player.serious = player.serious + 1
flag = true
}
default {
msg ("Wrong input, try again...")
}
}
}
}
Neonayon wrote:I guess that makes sense ---- hopefully then the player just doesn't type a bunch of misspellings lol!
So okay, I have the object: SwitchLoopResponse (in place where you had "control")
and an attribute on it called: SwitchLoop
Now when I looked at the code on your demo, it had...
...
So applying it to my game would look like...?
switch (LCase(result)) {
default {
do (SwitchLoopResponse, "SwitchLoop")
}
}
Which I would have to apply to all the default "switch" scripts correct? And as an attribute script on my "SwitchLoopResponse" object?
flag1 = true
flag2 = true
while(flag1){
if (flag2){
flag2 = false
//this makes sure the input doesn't repeat while the current one is active
get input{
switch (LCase(result)){
case(1){
//do stuff
//loop ends
flag1 = false
}
default {
//redo input
flag2 = true
}
}
}
}
}
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="while_loop_sample">
<gameid>paste or generate your own</gameid>
<version>1.0</version>
<start type="script">
fast_food_function
</start>
</game>
<object name="room">
<object name="player">
</object>
</object>
<function name="fast_food_function">
flag = false
while (!flag) {
msg ("Fast Food Menu:")
msg ("(1) hamburger")
msg ("(2) pizza")
msg ("(3) chicken")
msg ("(4) exit")
get input {
switch (result) {
case (1) {
msg ("Here's your hamburger!")
}
case (2) {
msg ("Here's your pizza!")
}
case (3) {
msg ("Here's your chicken!")
}
case (4) {
msg ("Have a good day, Sir/Ma'am.")
flag = true
}
default {
msg ("Wrong input, try again")
}
}
}
}
</function>
</asl>
<game name="xxx">
<start type="script">
do (SwitchLoopResponse, "SwitchLoop")
</start>
</game>
<object name="SwitchLoopResponse">
<attr name="SwitchLoop" type="script">
msg ("What is your personality?")
msg ("Your choices are (type one of these in): sexy, sympathy, sarcastic, snoopy, or serious")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a very serious tone.<br/>")
player.serious = player.serious + 1
}
default {
msg ("Wrong input, try again.")
do (SwitchLoopResponse, "SwitchLoop")
}
}
}
</attr>
</object>
<game name="xxx">
<start type="script">
do (SwitchLoopResponse, "SwitchLoop")
</start>
</game>
<object name="SwitchLoopResponse">
<attr name="SwitchLoop" type="script">
msg ("What is your personality?")
msg ("Your choices are (type one of these in): sexy, sympathy, sarcastic, snoopy, or serious")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a very serious tone.<br/>")
player.serious = player.serious + 1
}
default {
msg ("Wrong input, try again.")
do (game, "start")
}
}
}
</attr>
</object>
<game name="xxx">
<start type="script">
SwitchLoopResponse
</start>
</game>
<function name="SwitchLoopResponse">
msg ("What is your personality?")
msg ("Your choices are (type one of these in): sexy, sympathy, sarcastic, snoopy, or serious")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a very serious tone.<br/>")
player.serious = player.serious + 1
}
default {
msg ("Wrong input, try again.")
SwitchLoopResponse
}
}
}
</object>
<game name="xxx">
<start type="script">
do (SwitchLoopResponse, "SwitchLoop")
</start>
</game>
<object name="SwitchLoopResponse">
<attr name="SwitchLoop" type="script">
msg ("What is your personality?")
msg ("Your choices are (type one of these in): sexy, sympathy, sarcastic, snoopy, or serious")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a very serious tone.<br/>")
player.serious = player.serious + 1
}
default {
msg ("Wrong input, try again.")
do (SwitchLoopResponse, "SwitchLoop")
}
}
}
</attr>
</object>
does this make sense?
<game name="xxx">
<start type="script">
do (SwitchLoopResponse, "SwitchLoop")
</start>
</game>
<object name="SwitchLoopResponse">
<attr name="SwitchLoop" type="script">
msg ("What is your personality?")
msg ("Your choices are (type one of these in): sexy, sympathy, sarcastic, snoopy, or serious")
get input {
switch (LCase(result)) {
case ("sexy") {
msg ("<br/>“I’m not your husband, darling --- but I can see that he is a very lucky man.” you reply in a naturally sultry voice.<br/>")
player.sexy = player.sexy + 1
}
case ("sympathy") {
msg ("<br/>\"Err...that is, I'm not Rold, ma'am.\" you reply almost bashfully.<br/>")
player.sympathy = player.sympathy + 1
}
case ("sarcastic") {
msg ("<br/>“Well, either you can disguise your voice very well, or you’re not the one who let me in here…” you say with a sarcastic inflection.<br/>")
player.sarcastic = player.sarcastic + 1
}
case ("snoopy") {
msg ("<br/>“I’m sorry, I’m not he. But maybe you’d like to tell me who YOU are and what I’m doing here.” you say with curiosity.<br/>")
player.snoopy = player.snoopy + 1
}
case ("serious") {
msg ("<br/>“At least have the curtesy of turning around before addressing me. I’m not sure we’ve been properly introduced.” you say in a very serious tone.<br/>")
player.serious = player.serious + 1
}
default {
msg ("Wrong input, or you made a typo as you typed in your choice, please try again.")
do (SwitchLoopResponse, "SwitchLoop")
}
}
}
</attr>
</object>