Help with the 'Get Input' function?

TheDarkWyrm
This may be something that I should have learned from reading the tutorial, but is there a way to use

set (currency, "worth", 1000)

that kind of command to assign an attribute a value that isn't a number? I want to use the 'get input' function to change the player's name.

HegemonKhan
for example, let's say that your initial 'alias' is (in code): player.alias = "TheDarkWyrm", and you want to change it to "HK".

the syntax is the exact same, but for a String Attribute, you just need the 'Value' to have quotes on it:

set (Object, "Attribute'", "Value")

set (player, "alias", "HK")

or, an alternative script:

(in the GUI~Editor: run as script -> add a script -> Variables -> Set a variable or attribute)

Object.Attribute = Value_or_Expression

player.alias = "HK"

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

here it is in full:

in some script (for just the "player" Player Object in this example):

msg ("What is your new name?")
get input {
set (player, "alias", result)
msg ("Your new name is " + player.alias)
}

or

msg ("What is your new name?")
get input {
player.alias = result
msg ("Your new name is " + player.alias)
}


using both the 'get input' and 'show menu', automatically (internally by the quest engine core code) sets the built-in variable for you: result = your_selection

conceptually, quest (or any coding language for that matter) uses algebraic substitution:

msg ("What is your new name?")
get input {
-> // I'd type in: HK
-> // quest sets the built-in variable 'result' for you (you don't see it done): result = "HK"
-> // algebraic substitution below: player.alias = result = "HK -> player.alias = "HK"
-> player.alias = result
-> // your now new player's alias is: player.alias = "HK"
-> msg ("Your new name is " + player.alias + ".")
-> // outputs: Your new name is HK.
}

----------

(using a command)

<command name="alias_changing_command">
<pattern>newalias #object# and #text#</pattern>
<script>
if (object = null) {
msg ("That object doesn't exist. Try again.")
} else {
alias_changing_function (object,text)
}
</script>
</command>

<function name="alias_changing_function" parameters="object_x,text_x">
object_x.alias = text_x
msg ("The new name is" + object_x.alias)
</function>


... or ...

(using 'get input')

within some script:

msg ("What is your new name?")
get input {
player.alias = result
msg ("Your name is " + player.alias)
}


~ or ~

you can do the 'get input' within a Command too, but it's a bit pointless to do it this way.

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

String: a collection of characters, for examples:

a
1
dead
favorite_color_5
gfgv566dff3fknr04_8jh7hgfrd851

notice how the '1' is a String, but it is also an Integer...

an Integer, is an amount (non-decimal): ..., -100, -1, 0, 1 , 100, ...

an integer can be computed, for example:

old~initial Value: HK.strength = 25
HK.strength = HK.strength + 50
new Value: HK.strength = 75

so, numeral characters, can be a String or an Integer

in code, you can change between Strings and Integers:

Object.Attribute = Value

a String Attribute: HK.strength = "100"
an Integer Attribute: HK.strength = 100
(these both can't exist at the same time, as 'HK.strength' can only be one attribute type at a time)

Variable = Value

result_integer = ToInt (HK.strength)
result_string = ToString (HK.strength)

or

Object.Attrbute = Value

game.result_integer = ToInt (HK.strength)
game.result_string = ToString (HK.strength)

----------

in the GUI~Editor:

"whatever" Object -> Attributes (Tab) -> Attributes -> Add ->

As a String Attribute:
Attribute Name: strength
Attribute Type: string
Attribute Value: 100

As an Integer Attribute:
Attribute Name: strength
Attribute Type: int (integer)
Attribute Value: 100

-------

anyways, the reason this matters is that when using two or more Attributes together (in~for comparison usage), they must be the same type, else you get the 'infamous' error saying as such.

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

P.S.

this probably confused you, as this is a bit more in depth coding explanation, and I just don't explain that well to begin with.

so, feel free to ask about any questions you may have, or if you still having trouble, not understanding, and need better help.

Liam315
TheDarkWyrm wrote:This may be something that I should have learned from reading the tutorial, but is there a way to use

set (currency, "worth", 1000)

that kind of command to assign an attribute a value that isn't a number? I want to use the 'get input' function to change the player's name.



HK has answered your question but just to expand a little, your question is related to using expressions. In any expression field, anything you type "within quotation marks like this" represents a string. Anything without represents an internal value, whether it be an object name, True/False, an integer, or any variable (e.g. currency.worth).

So to use your currency example with other kinds of attributes:
set (currency, "number_of_coins", 8 ) - integer
set (currency, "weight", 2) - integer
set (currency, "legal_tender", False) - boolean
set (currency, "alternate_description", "You have never seen anything like these strange silver coins anywhere else before.") - string
set (currency, "total_weight", currency.weight*currency.number_of_coins) - integer (created by multiplying 2 variables)

You should also be aware that it is much easier to use the form object.attribute = value rather than the "set" function when you know what the name of the attribute is. The set function is better used in more advanced code when you don't know what the attribute name is going to be. So all of the above would be better expressed as:

currency.number_of_coins = 8
currency.weight = 2
currency.legal_tender = False
currency.alternate_description = "You have never seen anything like these strange silver coins anywhere else before."
currency.total_weight = currency.weight*currency.number_of_coins

Hope this helps.

Avantar
HK, just wanted to say super thanx for this: result_integer = ToInt :D

This made me super happy!

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

Support

Forums