Asking a question script.

Father thyme
16 Oct 2015, 11:22
Could some kind person explain to a non code understanding person how the script 'ask a question ' works. I understand that it offers the options yes or no but I cannot fathom how I can put in a choice of responses to y/n. I have written several games but never understood or used this option. I find problems finding out how things work . I either do things longhand or by trial and error. The explanations for dummies must be somewhere but I can never find them. For instance I don't even understand what 'expression ' means.

this is not that intuititive on how it works, so it's not your fault (it took me awhile to understand the 'ask' Script~Function~Verb too), but here's how it works:

// when you select 'yes' via the pop up menu, quest automatically (hidden from you), stores 'true' into the variable 'result' :
yes ---> result = true

// when you select 'no' via the pop up menu, quest automatically (hidden from you), stores 'false' into the variable 'result' :
no ---> result = false

(I'm trying not to do much in code for you, so hopefully this post will be of help to you)

// conceptually: if 'true', then do whatever script(s) 1:
add new script -> scripts -> 'if' Script -> if [EXPRESSION] result
// for the line above, just choose the [EXPRESSION] drop down choice, and literally just type in: result
-> then: -> add new script -> (whatever you want to do for when you answer~select 'yes')
// conceptually: else~otherwise, do whatever script(s) 2:
else -> add new script -> (whatever you want to do for when you answer~select 'no')

~or if you rather, you can do the opposite too:

// conceptually: if 'not true' (aka: if 'false' ), then do whatever script(s) 1:
add new script -> scripts -> 'if' Script -> if [EXPRESSION] not result
// for the line above, just choose the [EXPRESSION] drop down choice, and literally just type in: not result
-> then: -> add new script -> (whatever you want to do for when you answer~select 'no')
// conceptually: else~otherwise, do whatever script(s) 2:
else -> add new script -> (whatever you want to do for when you answer~select 'yes')

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

hmm...

'expression' is hard to explain...

I guess, think of an 'expression' as an incomplete~improper sentence, whereas a 'statement', is a complete~proper sentence (or a paragraph block), in programming terms.

x = 5 + 10
// x = 15

the (assignment) statement is: x = 5 + 10, the sum (verb~action, in this case, a calculation) of '5+10' (15) is stored into the variable 'x' (noun)

whereas, the expression is just: 5 + 10, a verb~action, but no noun is associated with it. You're doing the calculation verb~action of 5+10, but what are you doing with it's sum~result~answer of 15 ???

---------

and we've also got the simple~quick Value, as well:

x = 100 // a statement using just a Value, and not an Expression

'100' is obviously not an Expression, it's just a Value, there's no verb~action associated with the '100' itself, but the statement has a verb~action: the assignment (=): '100' is stored into the variable 'x'

--------

if (test_score > 90)

this is an expression (specifically the 'test_score > 90), whereas the statement is the full block of code (and there's also the individual statements within the 'if' block statement too):

this entire 'if' (if~else if~else) block is a statement:

if (test_score > 90) // an expression
{
grade = "A" // a statement
}
else if (test_score > 80) // an expression
{
grade = "B" // a statement
}
else if (test_score > 70) // an expression
{
grade = "C" // a statement
}
else if (test_score > 60) // an expression
{
grade = "D" // a statement
}
else
{
grade = "F" // a statement
}

I think XanMag and Father thyme should sit down for a few beers and discuss our coding woes! lol

I'm in the same boat. That's why I'm trying to build a tutorial game that is essentially a "Quest for Coding Dummies". Unfortunately, that does not help you yet, but if you are still confused after HKs, or others post(s), perhaps I will have a new 'chapter' for this topic that might be useful to you. In the meantime... Good luck!

XanMag

Father thyme
16 Oct 2015, 22:02
Sorry if I sound a bit dim but my coding dates back to Sinclair basic. I really don't understand modern coding or a lot of the technical terms. I just wanted to know what to put in the boxes having ticked script 'ask a question.' To get scripts for yes and no. Appreciate your explanation Hk but it is beyond my non mathematical mind. Thanks for your help.

Xm. you and I seem to try to work things out in the end by more luck and jiggerypokery than judgement , but we get great satisfaction in a successful result. Sometimes not the quickest or easiest, but the end result is the same.

for your 'ask' function~script, follow these 3 steps, do these 3 things:

I'm telling you *EXACTLY* how to do what you want via using the GUI~Editor's 'add new script' choices, just follow these 3 instructions!

add new script -> output -> 'Ask a question' Script -> (see below)

Ask question [TEXT] type_in_your_question_here
-> after choosing, run script -> (see the 3 steps below)

1. add new script (this is the grey rectangle button *INSIDE* the big blue highlighted box) -> scripts -> 'if' Script -> if [EXPRESSION] result
2. -> then: -> add new script -> (whatever you want to do for when you answer~select 'yes')
3. add else -> add new script -> (whatever you want to do for when you answer~select 'no')

~or if you rather, you can do the opposite too:

1. add new script (this is the grey rectangle button *INSIDE* the big blue highlighted box) -> scripts -> 'if' Script -> if [EXPRESSION] not result
2. -> then: -> add new script -> (whatever you want to do for when you answer~select 'no')
3. add else -> add new script -> (whatever you want to do for when you answer~select 'yes')

Father thyme
18 Oct 2015, 21:38
Thank you HK for your patience. I finally got it. Took me a while to realise that I had to install ' result' as a function in the game ( I never did functions before.)

no problem! Glad you got it! HK loves to help... but just gets frustrated at himself, when he fails to help people (as he often never does a good job at explaining, guiding step by step, or helping people ~ he usually just ends up confusing them more or scaring them away with code), GRR! :D

------

I hope you don't mean you actually created~added a Function... I hope it's just your terminology that is off, the 'result' is a built-in local VARIABLE (NOT an Attribute, which is a global VARIABLE).

------

ELEMENTS:
-> Objects (the special 'game' Game Object, Player Objects, Room Objects, non-player non-room Objects)
-> Exits
-> Verbs (GUI~Editor's Verbs anyways, as these "Verbs" are actually merely Objects' Script Attributes, in code)
-> Functions
-> Commands
-> Turnscripts
-> Timers
-> Object Types (Types ~ more confusing terminology, as this can get confused with people's general use of 'types' in talking about various code aspects)

VARIABLES:
-> Variable: local
-> Attribute: global (as long as the Object that contains~holds it, exists, of course)
-> Parameters: (mostly) local (but tied to Functions and Commands only)

DATA TYPES (of VARIABLES, generally associated most with Attributes):
-> string
-> int (integer; non-decimal number)
-> double (Floating Point: decimal number)
-> boolean (true~false)
-> script (these are the what the GUI~Editor's "Verbs" actually are in code)
-> char (character; individual characters~symbols)
-> lists (stringlists and objectlists)
-> dictionaries (stringdictionaries, objectdictionaries, scriptdictionaries)

SCRIPTING'S sources~containers:
-> Objects' and Object Types', Script Attributes ~ Verbs (GUI~Editor's)
-> Functions
-> Commands
-> Turnscripts
-> Timers

ya, the terminology is a bit confusing, sighs.

Father thyme
19 Oct 2015, 08:39
No I went to functions at the bottom of the tree and added result . Before that it just returned ' script error unknown function ' message.