12 Replies Latest reply on Dec 3, 2010 12:15 AM by JohannaFreeman

    how to use variables?



      how to use variables?



      i'm trying to use a variable to handle the hit points of a player of a basic text game:

      every time a specific calculation gives a result the variable gets +1 and display what happened

      on the combat field:

      Case ( defense="hit"; "hit!"....)

      I need to remeber the actual hit points status of the player, before adding any, so I need a variable to store the data. Simply, every time I got "hit" $health get +1.

      on the hit points field:

      Case ( defense="hit"; Let ($health = $health+1); ....)

      I know syntax is wrong but cant find out how to let this work

      thanks ^^

        • 1. Re: how to use variables?

          What you don't tell us here, is whether your case functions are being executed as part of a script or in a calculation field's definition and that makes a big difference here.

          Also:  there are $variables and $$variables. $Variables are local to a given script and values are not retained when the script ends. $$Variables are global and retain their values when the script ends. You also have the option of using unstored calculation fields instead of variables and these might be eiser to implement here.


          • 2. Re: how to use variables?

            I'm using calculation fields, but if its not possible I will go for a script.

            Its the same to use unstored calculation fields or variables to me as long as it works

            right now I have a stupid

            Let ($$health=1; $$health+1)

            as  health=health+1 is not accepted

            and which gaves always 2 when case "hit" happens...

            I would just need to add results and remember them somewhere, so that at like 10 hitpoints the game ends

            • 3. Re: how to use variables?

              Health = health + 1 is the syntax for incrementing a field rather than a variable.

              Let ( $$health = 1; $$health + 1 )

              Will always return 2 as you are setting the value to 1 then adding one every time.

              Try this variation and it may work:

              Let ( $$Health = If ( IsEmpty ( $$Health ) ; 1 ; $$Health ) ; $$Health + 1 )

              This will set $$Health to 1 only if the variable is empty such as when the file is first opened. If it's not empty, it will increment the value.

              • 4. Re: how to use variables?


                I've tried this code

                Case ( Health = "Hit";
                Let (
                $$Health = If ( IsEmpty ( $$Health ) ; 1 ; $$Health )
                ; $$Health + 1

                but it just display only "1" when the case "Hit" is calculated. Otherwise displays nothing.

                the code basicaly gives the same result as this:

                Case ( Health = "Hit";
                Let (
                Let ($$health=1; $$health+1)

                • 5. Re: how to use variables?

                  Is this part of a script step or something else? If part of something else, please describe how you've implemented it.

                  How are you displaying the value of $$Health?

                  It should be part of a merge text object on your layout such as <<$$Health>>. You'll probably need a Refresh Window script step to update the displayed value after every action that changes the value of $$Health.

                  • 6. Re: how to use variables?

                    the result is displayed as a field on the form (I've dragged the field tool on the form and then selected the field)

                    the results refresh after hitting a button which rolls dice

                    other fields make calculation upon the dice results and there is a field "Heath" which gives the "Hit" result.

                    (where are merge text objects on the tool bar?)

                    • 7. Re: how to use variables?

                      For merge text, click the layout text tool and type it in. Include the << and >>. (You might also want to look up "Inserting merge variables onto a layout" in FileMaker Help.

                      What kind of field? Is this a calculation field? (Not a number field with auto-entered calculation.)

                      If a calculation, is it Stored or Unstored?

                      • 8. Re: how to use variables?

                        It is a calcultion field and the result of the calculation is "number" (but not an autoentered calculation)

                        Where do i check if it is stored or unstored?

                        the result of the text tool <<$$Health>> gives laways 0

                        while the result of the calculation field gives 1 when the "Hit" happens otherwise nothing

                        • 9. Re: how to use variables?

                          When the field definition is open to the specify calculation dialog, click the storage options button and make this an unstored calculation to see if it makes any difference.

                          Personally, I'd use scripts with the Set Variable step to update $$Health instead of placing a Let function inside a calculation field. It's  lot simpler to control how the value changes.

                          • 10. Re: how to use variables?

                            I've tried this

                            if [TABLE:health = "Hit"]

                               set variable [$$Health;value:$$Health = $$Health+1]

                            End If

                            I refresh with a button calling this script

                            and then i display this with a text tool <<$$Health>>

                            again I just got zero as result

                            • 11. Re: how to use variables?

                              That because $$Health = $$Health + 1 is a logical ( boolean ) expression that is always false and the numerical value of "false" is zero.


                              Set variable [$$Health ; Value:  $$Health + 1 ]

                              • 12. Re: how to use variables?

                                It works! (I've added a refresh command to the script as you stated before to see changes)

                                Now to use the values of my variable

                                Case (
                                $$Health= "0" ;"Healthy";
                                $$Health="1" ;"Beaten Up";
                                $$Health="2" ;"Crashed";

                                ...$$Health="10" ;"Dead";


                                I call the variable into a calculation field unstored