Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

condition/if statement- fail :-(

edited January 2016 in Help! with 2.0
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

  • You have an invalid space character between the (if:) macro and it's associated hook [...]
    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
  • thank you, I will try it out!
  • so i fixed the code with your suggestions, but I still experience a rounding error at 0.3 . Is there anything I can do to override this? Or any other tips? Unfortunately, I do need to use the decimals in this story. The player is an archaeologist and must excavate in engineers feet. Worst case scenario, I can just leave it there as a bug but I'd rather not if I don't have to..... thank you for your advice!
  • edited January 2016
    Also, my if statement in the next bubble over isn't working. Do you know why that might be? this is the code I used. Not sure if I need to add something else. My other If statement elsewhere in the game, written in the same fashion, is fine. The difference between the two is that I have a piece of the story before this code that includes the statement described above (shown in red in the previously attached photo).

    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.
  • I have attached a Twine Archive file which contains two projects, you use Twine 2's Import From File option you add the projects to your instance of Twine 2.

    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:
    (if: $depthDigging is 0.10)[Text[[Action]]]
    
    (if: $depthDigging > 0.50)[text[[Action]]]
    
  • Forgot to attach the file. LOL
Sign In or Register to comment.