Set attribute values without numbers and can I do values with pointed numbers?
Curt A. P.
01 Nov 2017, 23:40Hi there, I am new to quest, one month or so. It's quite fun and there's a learning curve.
I created a dagger and want to give it the attribute "sharpness" and the values should be "sharp", "very sharp", "blunt", "dulled", etc.
Is there a way to do this? Would it be problematic?
Thanks and greetings.
Curtis

K.V.
02 Nov 2017, 00:24Hello!
dagger.sharpness = "sharp"
Or
dagger.sharpness = "verysharp"
Or
dagger.sharpness = "blunt"
Or
dagger.sharpness = "dulled"
if (dagger.sharpness = "verysharp"){
//Insert your script here
}
else if (dagger.sharpness = "verysharp"){
//Insert your script here
}
else if (dagger.sharpness = "blunt"){
//Insert your script here
}
else if (dagger.sharpness = "dulled"){
//Insert your script here
}
Or
switch (dagger.sharpness){
case ("sharp"){
//Insert your script here
}
case ("verysharp"){
//Insert your script here
}
case ("blunt"){
//Insert your script here
}
case ("dulled"){
//Insert your script here
}
}
Curt A. P.
02 Nov 2017, 02:43Oh well, I think this should work.
I don't get your 2nd example. Don't know could the switch script can help here. I used switch to handle different outcomes for the ShowMenu function, but I know where to find the switch tutorial. Still much need to learn...
The "If" solution looks easy for start. Thank you K.V.
Curt A. P.
02 Nov 2017, 03:01Okay, how could I change the value? I can't use the way I used till now, like the weight for example:
dagger.weight = dagger.weight + 1
But I guess this won't work to change the value "sharp" to "verysharp".

DarkLizerd
02 Nov 2017, 03:06"If" works well for testing for 1 out come...
IE:
if(player.human=true){
// this is a human player...
}
"Switch" could be called IF's big brother and works best when what you are testing can have several out comes...
and it works better than a chain of IF statements...
But... The nice thing about programming is... you can do it however is easiest for you...
( I wonder how many different ways a comparison statement could be worded???)
IE:
Is A larger than B???

DarkLizerd
02 Nov 2017, 03:21If use dulls the dagger then you could add a value called condition...
Then switch (or if chain) could determine how sharp the dagger is...
(not true code...)
if condition>90, then dagger.sharpness = "very sharp"
if condition>60, then dagger.sharpness = "sharp"
if condition>30, then dagger.sharpness = "blunt"
if condition>5, then dagger.sharpness = "dulled"
if condition>=0, then dagger.sharpness = "broken"

K.V.
02 Nov 2017, 03:23Whenever you want to change it, just do:
dagger.sharpness = "whatever_you_please_here"
Replace "whatever_you_please_here"
with "verysharp"
, "sharp"
, "dulled"
, or "blunt"
.
The switch
script should work identically to the if...then...
script, but, like DL says, "the nice thing about programming is... you can do it however is easiest for you."
(I couldn't get jack or squat out of a switch script for about a month, so don't feel bad!)

K.V.
02 Nov 2017, 04:20I've been messing around with your dagger...
I changed "verysharp"
to "very sharp"
to make it easier to print that value during play. (That's all I changed, though.)
If you get bored, you could create a new game, then open it in full Code View and paste this over what's there (then mess around with the scripts in the GUI):
CLICK HERE FOR THE EXAMPLE GAME'S CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="dagger">
<gameid>9dad1ef2-6c40-41cd-8802-2da085c41b09</gameid>
<version>1.0</version>
<firstpublished>2017</firstpublished>
<statusattributes type="stringdictionary">
<item>
<key>dagger_sharpness</key>
<value>The dagger is !.</value>
</item>
</statusattributes>
<start type="script"><![CDATA[
dagger.sharpness = "very sharp"
dagger.sharpness_values = Split("very sharp;sharp;dulled;blunt", ";")
game.dagger_sharpness = dagger.sharpness
msg ("<br/><center>{command:random:Randomize the dagger's sharpness attribute.}</center><br/>")
]]></start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="dagger">
<inherit name="editor_object" />
<feature_startscript />
<attr name="feature_usegive" type="boolean">false</attr>
<use type="boolean">false</use>
<take />
<look type="script"><![CDATA[
OutputTextNoBr ("It is "+dagger.sharpness+".")
switch (dagger.sharpness) {
case ("sharp") {
msg (" It could be sharper...")
}
case ("very sharp") {
msg (" It couldn't be any sharper!")
}
case ("blunt") {
msg (" It couldn't be any blunter!")
}
case ("dulled") {
msg (" It could be completely blunt, though. (It <i>might</i> still cut through soft butter.)")
}
}
]]></look>
</object>
</object>
<command name="change_dagger">
<pattern>random;random dagger;randomize dagger;randomize</pattern>
<script>
dagger.sharpness = PickOneString(dagger.sharpness_values)
msg ("The {object:dagger} is now "+dagger.sharpness+".")
</script>
</command>
<turnscript name="randomize_msg">
<enabled />
<script><![CDATA[
msg ("<br/><center>{command:random:Randomize the dagger's sharpness attribute.}</center><br/>")
]]></script>
</turnscript>
<turnscript name="status_update_for_dagger">
<enabled />
<script>
game.dagger_sharpness = dagger.sharpness
</script>
</turnscript>
</asl>
NOTE: Be sure to delete the existing code before pasting in the example code.
hegemonkhan
02 Nov 2017, 06:22if you want more detailed guide on this type of stuff:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
the 'if' Function/Script and the 'switch' Function/Script are exactly the same thing, just different looks/styles/patterns to them:
get input {
if (result = 0) {
// blah
} else if (result = 1) {
// blah
} else {
// blah
}
}
get input {
switch (result) {
case (0) {
// blah
}
case (1) {
// blah
}
default {
// blah
}
}
}
to alter integers (in-code scripting examples):
integer_variable = 0
integer_variable = 5
integer_variable = integer_variable + 3
integer_variable = integer_variable * 9
integer_variable = integer_variable - 7
integer_variable = integer_variable / 4
integer_variable = integer_variable + integer_variable_2
integer_variable = integer_variable_2
to alter strings (in-code scripting examples):
string_variable = "hi"
string_variable = "bye"
string_variable = string_variable + "okay"
string_variable = string_variable_2
string_variable = string_variable + string_variable_2
concept:
math/arithmetic addition vs string concatenation:
5 + 5 = 10
55 + 55 = 110
5 + "5" = ERROR!
5 + "hi" = ERROR!
"5" + "5" = "55"
"55" + "55" = "5555"
"5" + 5 = ERROR!
"hi" + "5" = "hi5"
"hi" + " " + "5" = "hi 5"
"hi " + "5" = "hi 5"
"hi" + " 5" = "hi 5"
"mama" + "mia" = "mamamia"
greeting = "hi"
msg (greeting)
greeting = greeting + ", my name is HK."
msg (greeting)
greeting = greeting + " What is your name?"
msg (greeting)
// output/results:
hi
hi, my name is HK.
hi, my name is HK. What is your name?
to alter/change/adjust/set/re-set/create/over-write/over-ride Attributes in the GUI/Editor:
run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
// Attribute VARIABLE usage:
set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION
// Variable VARIABLE usage:
set variable NAME_OF_Variable = [EXPRESSION] VALUE_OR_EXPRESSION
examples:
set variable player.strength = [EXPRESSION] 100
set variable player.alias = [EXPRESSION] "HK"
set variable orc.dead = [EXPRESSION] false
set variable katana.damage = [EXPRESSION] 50
set variable player.right_hand = [EXPRESSION] katana
set variable game.intro = [EXPRESSION] "welcome to my game, I hope you enjoy it, muwahahah!"
set variable game.intro = [EXPRESSION] game.intro + " This is a magical game, if you lose/die in this game, you die in real life!"
set variable player.damage = [EXPRESSION] player.right_hand.damage + player.right_hand.damage * player.strength / 100
Curt A. P.
06 Dec 2017, 20:15DarkLizerd
If use dulls the dagger then you could add a value called condition...
Then switch (or if chain) could determine >how sharp the dagger is...
(not true code...)
if condition>90, then dagger.sharpness = "very sharp"
if condition>60, then dagger.sharpness = "sharp"
if condition>30, then dagger.sharpness = "blunt"
if condition>5, then dagger.sharpness = "dulled"
if condition>=0, then dagger.sharpness = "broken"
I wonder how to make this "bigger as" and "smaller as" working correctly.
condition=>6
condition<=6
///with spaces?
I think I've started with too high ambitions for 1st project, so I pause it. Working on a prequel with a easier equipment system. I still want the condition states, so far.
hegemonkhan
5 + 5 = 10
55 + 55 = 110
So, one more question about values.
is it possible to use point numbers as a value get the maths working?
//Like this:
object.condition=object.condition + 0,3
// or + 0.3?

Doctor Agon
06 Dec 2017, 21:31Curt, What HK was trying to explain is that anything in ""'s is a separate string of letters and/or numbers. Joining two strings together, is like joining two sentences together, so:
"55" + "55" = "5555"
"How yo" + "u doing?" = "How you doing?"
"I'm gr" + "8" = "I'm gr8"
Joining a string to a number will produce an error.
You might have noticed the technique yourself and not realised what you were doing if you've completed the tutorial and done the section on 'saying'.

K.V.
06 Dec 2017, 21:51Doctor Agon speaks true, but did you mean adding an integer to a double?
integer = 2
double = .3
together = integer + double
msg (together)
If so, that works.
The output:
2.3

Doctor Agon
06 Dec 2017, 23:07Those are variables aren't they KV.
2 + 0.3 = 2.3
and not
integer double

K.V.
06 Dec 2017, 23:10Doesn't it make the integer a double when adding a double to it?
(I seriously don't know (but I assumed so), and I promise I'm not being a smart-arse.)
Curt A. P.
06 Dec 2017, 23:41You were impresively fast. Thx.
Okay, I see my post was a bit confusing.
My first question was just about to know how to type/use...
if condition>5
or
if condition>=5
...correctly in code. I shouln't copy-quoted the strings. Because, DarkLizerd said his example isn't true code.
My second question is anwered by K.V., I think... not sure yet.
My aim is to give objects a weight and a weight unit. My problem is the weight unit of my choice. It should be kg. I don't want to bother with "lbs" or "oz" since I can fast imagine what objects should weigh in "g" and "kg". Using "g" would lead to very big numbers for hevier objects and if I use "kg", but 1kg will be way too much for something like an apple. So, I need to make the appel's weight value being , let's say, 0.2kg.
Is what you try to show me, K.V., I need to puzzle the pointed numbers? Like making a "kg" value and a "g" value and fuse them somehow together?
SOMEHOW for the apple: 0kg + 200g = 0.2kg
Is this close to the right idea? lol
I know about the Volume feature but I want the weight unit kg.
Also, I want to use the volume feature to tell how much space a object consumes.
That should be like:
If I have, for example,
a sword which has a weigh of 4,60kg
and a Small Bag 3,00/9,00kg,
then I should be able to put the sword into the bag...NO, because the sword is to big for a small bag. Anyway, big weapons will only be stored in sheaths...

K.V.
06 Dec 2017, 23:51Edited:
game.string = "2"
game.integer = 2
game.double = 2.2
msg ("game.string = "+game.string)
msg ("game.integer = "+game.integer)
msg ("game.double = "+game.double)
msg ("")
msg ("game.intdbl = game.integer + game.double")
game.intdbl = game.integer + game.double
msg ("game.intdbl = "+game.intdbl)
msg ("")
msg ("game.strgdbl = game.string + game.double")
game.strgdbl = game.string + game.double
msg ("game.strgdble = "+game.strgdbl)
msg ("")
msg ("game.stringint = game.string + game.integer")
game.stringint = game.string + game.integer
msg ("game.stringint = "+game.stringint)
msg ("")
msg ("game.intstring = game.integer + game.string")
game.intstring = game.integer + game.string
msg ("game.intstring = "+game.intstring)
msg ("")
msg ("game.dblint = game.double + game.integer")
game.dblint = game.double + game.integer
msg ("game.dblint = "+game.dblint)
msg("")
msg ("game.dblstrg = game.double + game.string")
game.dblstrg = game.double + game.string
msg ("game.dblstrg = "+game.dblstrg)
msg("")
if(HasDouble(game, "intdbl")) msg("intdbl is a double.")
if(HasString(game, "intdbl")) msg("intdbl is a string.")
msg("")
if(HasDouble(game, "strgdbl")) msg("strgdbl is a double.")
if(HasString(game, "strgdbl")) msg("strgdbl is a string.")
msg("")
if(HasDouble(game, "stringint")) msg("stringint is a double.")
if(HasString(game, "stringint")) msg("stringint is a string.")
msg("")
if(HasDouble(game, "intstring")) msg("intstring is a double.")
if(HasString(game, "intstring")) msg("intstring is a string.")
msg("")
if(HasDouble(game, "dblint")) msg("dblint is a double.")
if(HasString(game, "dblint")) msg("dblint is a string.")
msg("")
if(HasDouble(game, "dblstrg")) msg("dblstrg is a double.")
if(HasString(game, "dblstrg")) msg("dblstrg is a string.")```
The output:
Curt A. P.
07 Dec 2017, 00:14Hm... smile
I've to gather more knowledge about this. I'm searching the Quest Documentation for some explanation about integer, double, intdbl, ect.
I can guess what this wil do, but I dont know what this means. lol
Maby it's a lack of my english, too.
Edit:
So, everything is a string or a double?
What is a double (for quest)?

K.V.
07 Dec 2017, 00:38A double is a number with a decimal point.
.2
is a double. 2.2
is a double.
2
is an integer.
I'm sorry, about the rest (intdbl and all that). I was adding integers to doubles (and each of those to strings) to see how Quest would react.
These are the actual attribute types:
(NOTE: There are more, but these apply to this case, I believe.)
-
string
game.fake_attribute_name = "2"
-
integer
game.fake_attribute_name = 2
-
double
game.fake_attribute_name = 0.2
If want to have kg and g, with function to convert kg to g:
<function name="ToKilograms" parameters="item" type="int">
if (HasDouble(item, "weight")) {
grams = item.weight*1000
grams = ToInt(ToString(grams))
return (grams)
}
else {
msg (item+": weight is not a double.")
return (item.weight)
}
</function>
To use it:
If you set up apple.weight as 0.2 (like this: apple.weight = 0.2
), you could do this to convert it to grams:
game.fake_attribute_name = ToKilograms(apple.weight)
Curt A. P.
07 Dec 2017, 03:01Oh, my head starts smokin'.
I get the doubles now.
K.V.:
Doctor Agon speaks true, but did you mean adding an integer to a double?
Ah, I missed that. Only problem is now can't change a double via 'math/arithmetic addition (so called?)'. I made a small test to pick up a marple and put ot into the pant's pocket. But then as I try to add the marple's weight to the pants I get a error.
if (GetBoolean(wearable_ordinary_pants__wool_001, "equipped")) {
ShowMenu ("Put the marple into your pant's pocket?", Split("yes;no", ";"), false) {
switch (result) {
case ("yes") {
MoveObject (marple, wearable_ordinary_pants__wool_001)
msg ("You put the marple into your pocket.")
set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001 + marple.kilogram)
}
case ("no") {
}
}
}
}
This lead to:
You are in your bedroom.
You can see a bed, a desk (on which there is a keyring), a pair of Leather Walking Shoes, a pair of Leather Boots, a mirror, a window, the bathroom door and a marple.>take marple
Put the marple into your pant's pocket?
1: yes
2: no>yes
You put the marple into your pocket.
Error running script: Error compiling expression 'wearable_ordinary_pants__wool_001 + marple.kilogram': ArithmeticElement: Operation 'Add' is not defined for types 'Element' and 'Double'

DarkLizerd
07 Dec 2017, 03:12"set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001 + marple.kilogram)"
Shouldn't that be:
set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001 + marple "kilogram")
or
set (wearable_ordinary_pants__wool_001.kilogram, wearable_ordinary_pants__wool_001 + marple.kilogram)
???
If not, why not???
Curt A. P.
07 Dec 2017, 03:13Oh, I forgot the to type the attribute for pants. Seems to work correctly now. The weight gets updated, too now. Thanks for the help.
I think the topic is solved for me.
Only thing I still don't understand how to type in...
object.kilogram>5
or
object.kilogram>=5
or
object.kilogram=>5
or
object.kilogram > = 5
//??????
...but there's no need for that now. Thx mates.
Curt A. P.
07 Dec 2017, 03:16DarkLizerd, you're right... lol
Damn. 04:14am here... zZzZZ

DarkLizerd
07 Dec 2017, 03:19(so, it does not mater??)
Curt A. P.
07 Dec 2017, 03:25What doesn't mater?
Na, the correct line was:
set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001.kilogram + marple.kilogram)
I forgot this one attribute.

DarkLizerd
07 Dec 2017, 03:39Funny that such a small thing would be such a problem...
So, I was "close"...
I did notice that the formula did not looks quite right...
So... would this work?
set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001 "kilogram" + marple "kilogram")

K.V.
07 Dec 2017, 04:33y = 6
if (y>=6){
msg("Y is greater than or equal to 6!")
}
else{
msg("Y is less than 6!")
}
After you turn something into a double, you have to do this to change it back (as far as I can figure out):
grams = 2
//NOTE - grams is now an integer
grams = grams + .2
//NOTE - grams is now a double
grams = grams*1000
grams = ToInt(ToString(grams))
//NOTE grams is an integer again
Curt A. P.
07 Dec 2017, 05:56Thx for the right example, K.V.
The second one, I don't understand this yet or see What it will be good for, sorry. And I'm not sure about needing a g-kg converter, but thx for the effort here.
Haven't found any errors with this:
if (GetBoolean(wearable_ordinary_pants__wool_001, "equipped")) {
ShowMenu ("Put the marple into your pant's pocket?", Split("yes;no", ";"), false) {
switch (result) {
case ("yes") {
MoveObject (marple, wearable_ordinary_pants__wool_001)
msg ("You put the marple into your pocket.")
set (wearable_ordinary_pants__wool_001, "kilogram", wearable_ordinary_pants__wool_001.kilogram + marple.kilogram)
}
case ("no") {
}
}
}
}
The marple moves into the inventory and the weight changes correctly.
More or less I made those items up to check the possibility to add a double with another double or integer. [For example: 2,3 + 0,8 = 3,1] And it works if I don't forget a attribute in the script and use dots instead of commas!
Result
You are in your bedroom.
You can see a bed, a desk (on which there is a keyring), a pair of Leather Walking Shoes, a pair of Leather Boots, a mirror, a window, the bathroom door and a marple.>look at Ordinary Wool Pants (worn)
Comfortable, warm pants made of fresh wool.
Good for sleeping.Weight: 0,98kg
No Protection
Flammable>take marple
You put the marple into your pocket.>Inv
You are carrying a pair of Ordinary Wool Pants (worn) (containing a marple).>look at Ordinary Wool Pants (worn)
Comfortable, warm pants made of fresh wool.
Good for sleeping.Weight: 0,99kg
No Protection
FlammableThe pants' pocket holds a marple.
>drop marple
You dropped a marple.>look at Ordinary Wool Pants (worn)
Comfortable, warm pants made of fresh wool.
Good for sleeping.Weight: 0,98kg
No Protection
Flammable
I haven't decided yet to handle intvory with this scripts. It's just scouting out before I do plenty of items with double attributes and afterwards I find out I couldn't adding double to double. But there's no problem. The pants have a weight of 0,98kg and the marple 0,01kg. Putting the marple into the pants raises the pants weight by the marples weight and reduces correctly if dropped.
By creating this first pocket I realized future problems with this script, but the weight will work I think, but this will be a future topic.
The game itself won't be a RPG. It will be more like a action adventure (Tomb Raider, Uncharted, Zelda classics, Jak and Daxter), but also some equipment management to do; the right gear at time. The player will gain more skills and powers by reaching setted goals, learning them by different ways and doing sidestuff (questing apart the mainstory). Also things can be missed and places could not be reached if you don't have certain skills, knowledge or gear. No exp. or leveling. No random encounters but different paths. Haha, I hope at least!
hegemonkhan
11 Dec 2017, 19:57ah cool a zelda (Z1: The Legend of Zelda: NES, Z3: A Link to the Past: SNES, and Z4: Link's Awakening: GB) like game... certainly do-able with quest... I've been thinking of trying to match such a game myself... but instead... I'm doing a TES-ambitious RPG... lol... it'll never get done... but it's a learning process... of game design, code design, and coding... and etc... hehe.
quest does have Floating Points (decimal/fractional numbers: ..., -9.456, -1.7, 0.0, 2.198, 999.86, ...) (called 'doubles' in quest) as Data Types, but I've never worked with them, so I don't know if they can be used with 'integer' Data Types directly or if you got to convert them to same data type... I try to use only 'integer' data types... but that is difficult, especially when you hate math and can't come up with how to do same stuff but without using decimal numbers, lol.
hegemonkhan
11 Dec 2017, 20:21you can't convert directly between an 'integer' and a 'double':
double to integer:
double_variable = 3.5
integer_variable = ToInt (double_variable)
// ERROR!
integer to double:
integer_variable = 3
double_variable = ToDouble (integer_variable)
// ERROR!
instead, you got to convert to a 'string' value as an inter-mediatary (can't spell / wrong grammer, lol) step:
double to string to integer:
double_variable = 3.5
string_variable = ToString (double_variable)
// you probably need to string manipulate script/function it (chop off, 'truncate', the '.5') , actually first... (or round up: 'ceiling', which would take a bit of different scripting, if you want to do this instead of truncating it: rounding issues/accuracy is complex stuff... would be fun/challenge to program scientific/graphic calculators... lol... at some point... maybe I'll try it... lol)
// stringlist_variable = split (string_variable, ".")
// truncated_string_variable = StringListItem (stringlist_variable, 0)
integer_variable = ToInt (truncated_string_variable)
// integer_variable = 3
// NO error
integer to string to double:
integer_variable = 3
string_variable = ToString (integer_variable)
// string_variable = "3"
concatenated_string_variable = string_variable + ".0" // string concatenation, literally putting '3' and '.0' together/next-to-each-other: "3.0"
double_variable = ToDouble (concatenated_string_variable)
// double_variable = 3.0
// NO error