Question about functions[Solved]

falconesabc
I've been trying to use the ToInt function, but it doesn't work. I get the error message Error running script: Function not found: 'ToInt'.

Help please. Where can I find the function/what do I need to do to make it?

The Pixie
It is probably the way you are using it. You need to use it like this:
s = "456"
n = ToInt(s)

If you do this:
ToInt(s)

... Quest will try to find a function with no return value, fail to find it and give the less-than-helpful error you report.

falconesabc
What I'm trying to do is get the action to perform in a loop, with the user inputting the number of times. So how would I do this?

It looks like ToInt won't be helpful

The Pixie
Like this:
msg("How many times?")
get input {
number = ToInt(result)
for (i, 1, number) {
msg("Iteration " + i)
}
}

falconesabc
Thanks

HegemonKhan
to expand upon Pixie's post, about the concept:

Attribute Type and Value Type matter

Strings are text (a collection/sequence of letters, numbers, and other symbols). Concatenation (literally putting together/next to each other) can be done on Strings/text

Integers/Doubles are amounts (arithmetic/math operations can be done on amounts) represented by non-decimal (integers) and decimal (doubles) numbers

String Atribute+Value: game.state = "0"
Integer (int) Attribute+Value: game.state = 0

game.state = "5"
game.state = game.state + 5
// ERROR! can't combine string:"5" and int:5, no comprehension!

game.state = 5
game.state = game.state + "5"
// ERROR! can't combine int:5 and string:"5", no comprehension!

game.state = "5"
game.state = game.state + "5"
// game.state = "55"

game.state = 5
game.state = game.state + 5
// game.state = 10

game.state = "mama"
game.state = game.state + 5
// ERROR! can't combine string:"mama" and int:5, no comprehension!

game.state = "mama"
game.state = game.state + "5"
// game.state = "mama5"

game.state = "mama"
game.state = game.state + "mia"
// game.state = "mamamia"

---------

get input: converts whatever you type in (into the command/text box during game play) into a String Value, and automatically stores it into the built-in 'result' Variable

result <- returned/outputted String Value <- get input () <- (your typed-in input)

get input {
// your typed-in input is converted into a String Value, by the 'get input' Script/Function
// automatically (hidden from you) sets/stores your String Value into the built-in 'result' Variable: result = (your typed-in input)
msg (result)
}


-------

ToInt (String Value): converts the intputted String Value into a returned/outputted Integer (int) Value

VARIABLE <- returned/output Integer Value <- ToInt (input String Value)

game.state_string = "0"
game.state_integer = ToInt (game.state_string)
// game.state_integer = 0

------

and then your other question was on how to do iteration (cycling), which Pixie already covered.

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

Support

Forums