Needing quick help with "If" script
Asyranok
19 Feb 2013, 19:53I can't find the answer in the tutorials, and I tried searching fro previous posts, but the search function said all of my key words were too common to use.
I have an "If" script function. I want to know how to properly make it so that I can include "and" so that multiple values satisfy the if statement.
So, for example:
If ---Object------attribute value----- equals-----5
Then Print Message
Elseif----Object-----attribute value---- equals----- 1, 2, 3, or 4
How do I do this?
Thanks!
I have an "If" script function. I want to know how to properly make it so that I can include "and" so that multiple values satisfy the if statement.
So, for example:
If ---Object------attribute value----- equals-----5
Then Print Message
Elseif----Object-----attribute value---- equals----- 1, 2, 3, or 4
How do I do this?
Thanks!
HegemonKhan
19 Feb 2013, 21:14If you're using the GUI~editor mode, probably the only way is with using: Print A Message [EXPRESSION] scripts, as this lets you type in the code that you want directly (I'd try to learn to work directly with writing and understanding the code, as it is so much easier and faster than using the GUI~editor, once you start to learn it and all the code inputs).
so, here's an example:
"code1" : orc.monster = true
"code2" : orc.parent = player.parent
If... -> Print A Message [EXPRESSION] -> orc.monster = true and orc.parent = player.parent -> then ->
-> Call Function -> Player_Attack_Monster_Function
(also notice how code1 is actually code1A : orc.monster, = , code1B : true)
(also notice how code2 is actually code2A : orc.parent, = , code1B : player.parent)
(so there's actually multiple layers, math term: fractalizing, of " codeX ??? codeY " )
[codeX] ??? [code Y]:
[orc.monster] = [true]
[orc. parent] = [player.parent]
[orc.monster = true] and [orc.parent = player.parent]
so all you got to do, is to use Print A Message [EXPRESSION] and then simply use~type in, "and" or "or" or ">" or "<" or "=" or "<>" or "<=" or ">=" to connect~compare~contrast things together
in Code View mode:
If (code1 ??? code2) {
-> (then whatever scripting of~for what you want done to be done or achieved)
}
??? = the below choices:
and : combining
or : independantly
= : same~equal
<> : not same~equal
> : greater than
< : less than
=> : equal and greater than
=< : equal and less than
there's also a little button on the right of when you're doing the the "Print A Message" which you can press to give you these same choices, but simply typing them in is easier, lol
----------
also, your other question:
in GUI~editor mode, a (badly done but it serves its purpose) example:
Orc -> Verb (Tab) -> Add A Verb -> Attack
If... -> Print A Message [EXPRESSION] -> orc.monster = true and orc.parent = player.parent -> then ->
-> Call Function -> Player_Attack_Monster_Function
Else -> If.. -> Print A Message [EXPRESSION] -> orc.monster = false -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " is not an enemy! You can not attack " + orc.alias +"!"
Else -> If... -> Print A Message [EXPRESSION] -> orc.parent <> player.parent -> then ->
-> Print A Message [EXPRESSION] -> "There is no " + orc.alias + " in the vicinity."
---------
if you want to include a range of numbers (another bad example but it serves its purpose):
If... Print A Message [EXPRESSION] -> orc.speed >= 0 and orc.speed < 50 -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " is too slow to catch you!"
Else -> If... Print A Message [EXPRESSION] -> orc.speed >= 50 and orc.speed <= 100 -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " catches you, and then eats you!"
-> Print A Message [MESSAGE] -> "GAME OVER"
-> End Game Script Choice (whatever it is called)
so, here's an example:
"code1" : orc.monster = true
"code2" : orc.parent = player.parent
If... -> Print A Message [EXPRESSION] -> orc.monster = true and orc.parent = player.parent -> then ->
-> Call Function -> Player_Attack_Monster_Function
(also notice how code1 is actually code1A : orc.monster, = , code1B : true)
(also notice how code2 is actually code2A : orc.parent, = , code1B : player.parent)
(so there's actually multiple layers, math term: fractalizing, of " codeX ??? codeY " )
[codeX] ??? [code Y]:
[orc.monster] = [true]
[orc. parent] = [player.parent]
[orc.monster = true] and [orc.parent = player.parent]
so all you got to do, is to use Print A Message [EXPRESSION] and then simply use~type in, "and" or "or" or ">" or "<" or "=" or "<>" or "<=" or ">=" to connect~compare~contrast things together
in Code View mode:
If (code1 ??? code2) {
-> (then whatever scripting of~for what you want done to be done or achieved)
}
??? = the below choices:
and : combining
or : independantly
= : same~equal
<> : not same~equal
> : greater than
< : less than
=> : equal and greater than
=< : equal and less than
there's also a little button on the right of when you're doing the the "Print A Message" which you can press to give you these same choices, but simply typing them in is easier, lol
----------
also, your other question:
in GUI~editor mode, a (badly done but it serves its purpose) example:
Orc -> Verb (Tab) -> Add A Verb -> Attack
If... -> Print A Message [EXPRESSION] -> orc.monster = true and orc.parent = player.parent -> then ->
-> Call Function -> Player_Attack_Monster_Function
Else -> If.. -> Print A Message [EXPRESSION] -> orc.monster = false -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " is not an enemy! You can not attack " + orc.alias +"!"
Else -> If... -> Print A Message [EXPRESSION] -> orc.parent <> player.parent -> then ->
-> Print A Message [EXPRESSION] -> "There is no " + orc.alias + " in the vicinity."
---------
if you want to include a range of numbers (another bad example but it serves its purpose):
If... Print A Message [EXPRESSION] -> orc.speed >= 0 and orc.speed < 50 -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " is too slow to catch you!"
Else -> If... Print A Message [EXPRESSION] -> orc.speed >= 50 and orc.speed <= 100 -> then ->
-> Print A Message [EXPRESSION] -> orc.alias + " catches you, and then eats you!"
-> Print A Message [MESSAGE] -> "GAME OVER"
-> End Game Script Choice (whatever it is called)
TriangleGames
19 Feb 2013, 21:21Asyranok wrote:...
I have an "If" script function. I want to know how to properly make it so that I can include "and" so that multiple values satisfy the if statement.
So, for example:
If ---Object------attribute value----- equals-----5
Then Print Message
Elseif----Object-----attribute value---- equals----- 1, 2, 3, or 4
...
It looks to me like your statement does not match your example. If scripts should automatically include a button labeled "+ Add Else If" for alternative conditions. Using "and" in an if statement would mean that two separate conditions both have to be true in order for the overall statement to be true. For example, let's say the player is trying to start a car. You might have something like
"IF the car has gas AND the car has been repaired, THEN the car starts"
(NOTE: that is not proper code, it's just an example of an If, AND logic statement)
I had some trouble finding the documentation on that myself due to the short words involved, and I forget how I eventually found it, but I did. Unless I am mistaken, the only way to literally use an IF, AND statement is to write out the actual expression instead of selecting a condition from the drop menu. However, you can get the same effect by nesting IF statements, like so:
Switch On Car, Run Script:
IF---Object: Car---Attribute: has fuel---Equals: true
THEN, Run Script:
___IF---Object: Car---Attribute: is repaired---Equals: true
___THEN---Set Object: Car---Attribute: "is on"---Value: true
___ELSE---Print: "The car's engine is broken."
Else---Print: "The car has no gas."
Does that make sense?
Asyranok
20 Feb 2013, 00:58Hey guys, thanks for the advice.
Your advice has helped me fix 99% of what was ailing me, but something isn't working right for me, unrelated to If/Else statements
In the following code, clicking on this object will bring up a menu. In the menu, 8 options are available. You can move the object to any order out of 8 that you want. It works exactly as I need it to, except for one small problem. When I play the game, I cannot change the attribute ".order" to a value of 8. When I tell it to chance to 1, 2, 3, 4, 5, 6, or 7 - it works. But when I tell it to change to 8, it stays at the previous value. What is wrong in my code? I suspect it is a syntax issue in the topics(split) line. Any ideas? Thanks!
To test in game, a quick walkthrough would be :
1. When control is granted, talk to Duffy
2. Talk to Duffy again with new conversation topic
3. Proceed through scripted segment until control is granted again, in Medical Station
4. Click on "strange object" and choose to touch it
5. Look at flashing lights
6. Choose to move constellations to whatever order you like
7. Check that orders have been changed via the "Help Beacon" and "View order with help".
8. Note that all orders change correctly except for 8 out of 8
Your advice has helped me fix 99% of what was ailing me, but something isn't working right for me, unrelated to If/Else statements
In the following code, clicking on this object will bring up a menu. In the menu, 8 options are available. You can move the object to any order out of 8 that you want. It works exactly as I need it to, except for one small problem. When I play the game, I cannot change the attribute ".order" to a value of 8. When I tell it to chance to 1, 2, 3, 4, 5, 6, or 7 - it works. But when I tell it to change to 8, it stays at the previous value. What is wrong in my code? I suspect it is a syntax issue in the topics(split) line. Any ideas? Thanks!
To test in game, a quick walkthrough would be :
1. When control is granted, talk to Duffy
2. Talk to Duffy again with new conversation topic
3. Proceed through scripted segment until control is granted again, in Medical Station
4. Click on "strange object" and choose to touch it
5. Look at flashing lights
6. Choose to move constellations to whatever order you like
7. Check that orders have been changed via the "Help Beacon" and "View order with help".
8. Note that all orders change correctly except for 8 out of 8
<object name="Constellation02">
<inherit name="editor_object" />
<alias>Constellation Goyo Vignat</alias>
<look><![CDATA[<br/>This constellation marks a creature with two very long hind legs, and two short front appendages. The nails on the feet are long and curved upwards. The claws on the front appendages are vestigial, with digits that seem to be used for grabbing things, without large nails getting in the way. The creature appears to walk on its hind legs most, or all of the time. <br/><br/>A tail extends that is long and thin, but is quite muscular and obviously capable of being used as a whip, or for grabbing and holding onto things. <br/><br/>The creature's rear teeth are virtually flat, while its front teeth are wedge-shaped, and a few fangs lie at the tip of its snout.]]></look>
<displayverbs>Look at</displayverbs>
<order type="int">2</order>
<correctvalue type="int">8</correctvalue>
<move type="script"><![CDATA[
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot";")
msg ("<br/>The creatures described by each constellation must be place in order of which is the most ancient ( spot 1 out of 8), to which evolved latest, (spot 8 out of 8). You can give each constellation the same order value, but in finding the correct order, each constellation will need to have a different order value between 1 and 8.<br/>")
msg ("This constellation is currently sitting in position " + Constellation02.order + " out of 8.")
msg ("<br/>")
show menu ("\"Which spot do you wish to place this constellation in?\"", topics, false) {
switch (result) {
case ("Move to first spot") {
Constellation02.order = 1
}
case ("Move to second spot") {
Constellation02.order = 2
}
case ("Move to third spot") {
Constellation02.order = 3
}
case ("Move to fourth spot") {
Constellation02.order = 4
}
case ("Move to fifth spot") {
Constellation02.order = 5
}
case ("Move to sixth spot") {
Constellation02.order = 6
}
case ("Move to seventh spot") {
Constellation02.order = 7
}
case ("Move to eigth spot") {
Constellation02.order = 8
}
}
msg ("This constellation is now sitting in position " + Constellation02.order + " out of 8.")
}
HegemonKhan
20 Feb 2013, 08:07still looking over your code, but this is wrong format for your split script:
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot";")
correct(ed) format (with the spaces):
(the spaces below work, but you shouldn't use spaces like this as sometimes it causes the code to not work, I put them in, so you can better see the comma and semicolon)
topics = Split ("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot" , ";")
correct(ed) format (without the spaces):
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot",";")
--------------------
The way the split code works is that the:
split ( "??? ; ??? ; etc"
are your choices ("list) of individual strings
and this:
, ";" )
is telling that the separation of those individual strings (your choices) is the semicolons, as this is needed by the quest engine.
so it's like this:
split ("choice1 X choice2 X etc" , "what is the separator of the choices?")
X = your choosen separator
split ("choice1;choice2;etc",";")
----------------
http://quest5.net/wiki/Split
Split ( string input , string split character )
Returns a stringlist where the input has been split into individual strings by the split character. Useful for turning a comma-separated string into a list of strings, for example.
---
http://quest5.net/wiki/Stringlist
<mylist type="list">one; two; three</mylist>
A stringlist is a list that can contain a number of elements, all have to be of type string.
----------------------------------------
another mistake:
a simple typo by you causing them to not match up (ARGH! hehe):
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot";")
notice how 8th is spelled in the above: Move to eighth spot = eighth = 2H's
now notice how 8th is spelled here: case ("Move to eigth spot") { = eigth = 1H
your case is looking for 8th with 1H, while your choice of 8th has 2H's, and thus it can't find any choice of an 8th of 1H, hehe.
> when you code write, you have to be 100% typo free, and perfect in all syntax and formatting, lol.
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot";")
correct(ed) format (with the spaces):
(the spaces below work, but you shouldn't use spaces like this as sometimes it causes the code to not work, I put them in, so you can better see the comma and semicolon)
topics = Split ("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot" , ";")
correct(ed) format (without the spaces):
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot",";")
--------------------
The way the split code works is that the:
split ( "??? ; ??? ; etc"
are your choices ("list) of individual strings
and this:
, ";" )
is telling that the separation of those individual strings (your choices) is the semicolons, as this is needed by the quest engine.
so it's like this:
split ("choice1 X choice2 X etc" , "what is the separator of the choices?")
X = your choosen separator
split ("choice1;choice2;etc",";")
----------------
http://quest5.net/wiki/Split
Split ( string input , string split character )
Returns a stringlist where the input has been split into individual strings by the split character. Useful for turning a comma-separated string into a list of strings, for example.
---
http://quest5.net/wiki/Stringlist
<mylist type="list">one; two; three</mylist>
A stringlist is a list that can contain a number of elements, all have to be of type string.
----------------------------------------
another mistake:
a simple typo by you causing them to not match up (ARGH! hehe):
topics = Split("Move to first spot;Move to second spot;Move to third spot;Move to fourth spot;Move to fifth spot;Move to sixth spot;Move to seventh spot;Move to eighth spot";")
notice how 8th is spelled in the above: Move to eighth spot = eighth = 2H's
now notice how 8th is spelled here: case ("Move to eigth spot") { = eigth = 1H
your case is looking for 8th with 1H, while your choice of 8th has 2H's, and thus it can't find any choice of an 8th of 1H, hehe.
> when you code write, you have to be 100% typo free, and perfect in all syntax and formatting, lol.
Asyranok
20 Feb 2013, 20:19Hagemon, thanks again. You are clutch. I appreciate you going out of your way to help me, and explain my mistakes!