I am trying to set up an If statement. I have two problems. The first, is that I need to use a decimal point number. This works, to a point, for some reason when the number should read .30, it ends up reading .3000000 (and some more numbers). The more problematic issue is that I need to set a condition that will allow the user to click the statement a certain number of times, until they reach .5. Once they reach the .50 number, I want the "Keep Digging" option to dissapear, so that they are only left with the one option- to "Start Troweling." Here is the code I'm using, which I copied from a tutorial. It works in the tutorial, but wondering if may be I'm missing something else, or need to add some code elsewhere in another block of text.... Let me know, I'm a newbie so be kind! :-) The red block, I was told, is a glitch in Harlow but that the story will still run. It ran ok in the tutorial. I'm using 2.0.8 but I'm not sure which version of 2 the tutorial was set for:
[img][/img]
Do you want to keep digging or do you want to begin screening soil?
(set: $depthDigging to $depthDigging + .10)
You have excavated $depthDigging feet.
(if: $depthDigging < .50)
[Keep digging]
Begin Troweling
Comments
Remove that space character and your example will work.
notes:
a. Generally it is better not to use decimal (floats) numbers unless you really need to, because as you noticed in your example they can produce rounding errors.
eg. add 0.1 to 0.2 in your example and the result is 0.30000000000000004
b. Generally decimal number literals between 0 and 1 (or 0 and -1) include a 0 before the decimal point. eg. 0.1 or 0.5
c. Generally trailing 0's are meaning less in decimal numbers and are not used.
eg. 0.500 and 0.50 and 0.5 are the same number, so use 0.5
In the red box (shown in pic above) the code reads:
(set: $depthDigging to $depthDigging + 0.10)
You have excavated $depthDigging feet.
(if: $depthDigging < 0.50)[Keep digging]
Begin Troweling
Begin screening soil
In the box right to the red box (shown in the pic above) the code reads:
(if: $depthDigging is 0.10)[TextAction]
(if: $depthDigging > 0.50)[textAction]
When I run it in bug mode, the problem is still with the red box. Ideas? The problem now is that once I'm left with the Begin Troweling option, the next box is blank. No more text appears.
1. thilliard example: This is a working copy of your example, I did not need to change anything in your code to make it work.
If you set the $depthDigging variable in the Startup passage to 0 and navigate to the Begin Troweling passage then you will see the first line of text and a link. If you then change the $depthDigging variable in the Startup passage to a number greater than or equal to 0.5 then you will see the second line of text and link in the Begin Troweling passage.
2. greyelf suggestion: This shows you how to use an integer to simulate a decimal (floating point) number, the example only converts the integer into a decimal when it is displayed to the reader. If you set the $depthDigging variable in the Startup passage to 2 then you will see it display 0.3 correctly.
note: You should use the C button in comment toolbar to wrap code examples in your comments, it makes them easier to read like so: