Is it possible to set attribute values without numbers?

Hi 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


Hello!

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
  }
}

Oh 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.


Okay, 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".


"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???


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"


Whenever 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!)


I'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.


if 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


Log in to post a reply.

Support

Forums