This is true for many languages I’ve looked at: If there are no example cases then I’m totally lost. I’ve even googled how to read docs and there is very little help.
So as a quick example, I want to do this:
class Test {
static function main() {
trace("Enter a number between 1 and 10: ");
var entry = Sys.stdin().readLine();
// Parse string to number and place into [new?] variable
var newEntry = ???
}
}
According to the doc API’s I am lead to the Std page:
https://api.haxe.org/Std.html
static parseInt (x:String):Null<Int>
How do you know what needs to be typed, what needs to be replaced, and what is there for information only.
- First, look at the API page that your code example falls into. In this example it’s “Std” class without the quotes.
- Then add a dot “.”
- “Static” is information. It is not typed.
- “parseInt” is the method. Type without quotes.
- Opening parenthesis.
- Place your string in quotes or your variable that has string information. Replace “x:String” (expected input) completely.
- Closing parenthesis
- Everything to the right, including the “:”, is information (expected output) and is not to be typed.
So the final method looks like this
Std.parseInt(entry);
If you want it to do something useful, assign it to a new variable:
var newEntry = Std.parseInt(entry);
You might want to check out the beginner section on the code cookbook.
It has this article which demonstrates how you can deal with numbers: