Using GetInput

Forgewright
when using GetInput, in the result line of code how do I separate different responses that mean the same thing?

if (result = "fly; start flying; flap wings; zoom") // these are command triggers the player uses in regular play but this is a special response to a fall and if the result is not one of these responses they will die.//

is it commas or can I even have more than one.......

HegemonKhan
unfortunately, the format-syntax-pattern requires a good bit more typing...

------------

if (result = "fly" or result = "start flying" or result = "flap wings" or result = "zoom") {
// blah scripts
}

-------------

examples:

if (result = "xxx" or result = "xxx" or result = "xxx") {
// blah scripts
}

OR, using Attributes, an example:

if (player.strength = 50 or player.endurance = 50 or player.dexterity = 50) {
// blah scripts
}

another Attribute example:

if (player.strength >= 67 and player.strength <= 100) {
msg ("You have great strength.")
} else if (player.strength >= 34 and player.strength < 67) {
msg ("You have average strength.")
} else if (player.strength >= 0 and player.strength < 34) {
msg ("You have weak strength.")
}


----------

also, you understand the differences+concepts between using:

'and'
'or~xor'
'not'

right?

--------

get input {
if (result = 5 or result = 10) {
msg ("hi")
}
}


if you type in '5', outputs: hi
if you type in '10', outputs: hi
if you type in any other number, outputs: null (nothing)

-----

Command Pattern: add #text1# and #text2#
Scripting: (see below)

if (item1 = 5 and item 2 = 10) {
msg ("5+10=15")
}


if you type in for #item1# as '5' and #item2# as '10', output: 5+10=15
if you type in for #item1# as '5' and #item2# as '15', output: null (nothing)
if you type in for #item1# as ''15' and #item2# as '10', output: null (nothing)

jaynabonne
You can also use a switch statement:

      get input {
switch (result) {
case ("fly", "start flying", "flap wings", "zoom") {
msg ("You take off")
}
case ("land") {
msg("You stop flying")
}
default {
msg("You die")
}
}
}

The Pixie
You could use Regex pattern matching in your switch:
get input {
switch (True) {
case (IsRegexMatch("(fly|flap|zoom)", result)) {
msg ("You start to fly")
}
case (IsRegexMatch("land", result)) {
msg ("You land on the ground")
}
default {
msg ("Nothing happens")
}
}
}

http://docs.textadventures.co.uk/quest/ ... ching.html

Forgewright
HegemonKhan, Really? a freakin "or"... luv it.....

Jaynabonne , Never thought about the switch.......

Pixie, IsRegexMatch.... seen it....never used it.....looks like I have my new subject to practice this week.

Thanks Folks.

I am constantly seeing new (to me) creative ways of using code. Is there a site (other than) textadventures.co.uk that showcases new and innovative code usage that makes other experienced coders say, "Wow!"

HegemonKhan
Forgewright wrote:HegemonKhan, Really? a freakin "or"... luv it....


I'm terribly sorry, I didn't mean to offend at all, I was just asking if you already knew about the concepts of 'and~or~xor~not', as they're a bit advanced concepts and diffcult to understand+use correctly for most people (especially anyone new to coding). So again I'm sorry for any offense to you, it was never intended.

Forgewright
:lol: Lol Hege, I was just surprised and/or excited that it was so simple a fix. No offense taken friend. That previous post was just a little sarcasm.... Thanks for the help. Forums are texting after all and easy to misunderstand a persons feeling/emotions... :D I'll have to start using the emoticons.....
I am always thankful to everyone here for the guidance and patience. Just tell me where to send the check.....Nyuck nyuck

HegemonKhan
I was leaning that it was sarcasm, but jsut in-case it wasn't, I posted that post. I perceive things differently than most people, regardless of being text or in person, laughs, so don't worry about it. I misunderstood and~or was being cautionary, that is all.

-------

well, it isn't intuitive... because you got to write the entire expression (except for the 'if' as it is outside of the parenthesis: it is already applied to the entire expression), again and again with your 'or' and~or 'and' in-between the repeated full (excluding the 'if' part) expressions.

This can become quite a lot of typing... while simple (once you get the syntax)... you'd be better off using for~foreach + lists~dictionaries, than you manually writing out all those expressions-conditions, yourself...

------

laughs... as for the "check~cash~reward" for our help... instead, just make an awesome game (free or priced) for us to play~enjoy, hehe :D

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

Support

Forums