Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Goto or jump functions

    Coding
    5
    22
    934
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mechanical last edited by

      Okay so just for everyone with the same problem, here is what I've learned now:

      A function isn't the same as goto but much more versatile. It can do the same but much better. Therefore goto isn't needed in F4.

      Everyone who misses goto should read about functions.

      Thread can be closed

      P 1 Reply Last reply Reply Quote 4
      • P
        petermeisenstein F @Mechanical last edited by

        @Mechanical threads get only closed if its going away from the topic. I think

        1 Reply Last reply Reply Quote 0
        • P
          petermeisenstein F last edited by

          @Mechanical https://fuzearena.com/forum/topic/1099/a-goto-workaround That may will help you

          1 Reply Last reply Reply Quote 0
          • PickleCatStars
            PickleCatStars F last edited by PickleCatStars

            Functions are great! Once you get used to them, you’ll never want to go back.

            Also give structs a try. They’re the ones that look like player.pos player.colour player.shiptype etc. Comes in handy, makes your stuff more readable too :)

            P 1 Reply Last reply Reply Quote 1
            • P
              petermeisenstein F @PickleCatStars last edited by

              @toxibunny Exactly nevertheless I made a goto workaround how may will help persons who miss theyre goto and so they can feel a bit better in fuze

              1 Reply Last reply Reply Quote 0
              • M
                Mechanical last edited by

                I've asked myself if I couldn't write a complete function for my Main Screen, Game Screen ect.

                If I scripted that on ROMs I just would do this

                @Maintext // Stores text data
                " This is the Main Screen"
                @Gametext // Same
                "This is the Game"
                @IntroAsk
                "Do you want to play?"

                Start
                Msgbox 6,@Maintext /shows text data

                Msgbox 5,@IntroAsk / ask yes no question
                If LASTRESULT 1 goto @Gamescreen

                @Game Screen
                Msgbox 6,@Gametext

                End

                P Martin 2 Replies Last reply Reply Quote 0
                • P
                  petermeisenstein F @Mechanical last edited by

                  @Mechanical Yeah sure but you cant jump with this
                  @ example

                  Maybe you should read the chapter about functions

                  1 Reply Last reply Reply Quote 0
                  • Martin
                    Martin Fuze Team @Mechanical last edited by

                    @Mechanical said in Goto or jump functions:

                    I've asked myself if I couldn't write a complete function for my Main Screen, Game Screen ect.

                    If I scripted that on ROMs I just would do this

                    @Maintext // Stores text data
                    " This is the Main Screen"
                    @Gametext // Same
                    "This is the Game"
                    @IntroAsk
                    "Do you want to play?"

                    Start
                    Msgbox 6,@Maintext /shows text data

                    Msgbox 5,@IntroAsk / ask yes no question
                    If LASTRESULT 1 goto @Gamescreen

                    @Game Screen
                    Msgbox 6,@Gametext

                    End

                    I think you need to work your way through some of the tutorials! This isn't ROM (don't know what that is - well, I know what a ROM is, but I know you're not talking about that)

                    Things just don't work in the same way here! For starters there isn't really a start to finish flow of things, you need a loop that runs forever

                    Very loosely (pseudo-code to a certain extent) you would have:

                    mainText = "This is the Main Screen"
                    gameText = "This is the Game"
                    introAsk = "Do you want to play?"
                    
                    // This is not real code!
                    loop
                        while attract
                            clear()
                            // Ask if they want to play a game
                            update()
                        repeat
                    
                        while play
                            clear()
                            // Play the game
                            update()
                        repeat
                    repeat
                    
                    1 Reply Last reply Reply Quote 0
                    • M
                      Mechanical last edited by

                      Okay I can say that I understand it to a certain extend now.

                      Rn I wrote a function that is my Main Game Engine. This Engine can be extended and improved by altering the function itself and will start after setting the needed Parameters in a main menu.

                      Here is what I learned the last time I used them:

                      If I want to Improve the Engine, every Variable that is used in the function itself must be determined in a Library before it is used in the function. Otherwise the compiler tells me that the Variable doesn't exist.

                      On the other side that means every Variable that's been defined inside of a function will Vanish after the Function is being executed. They only exist to work for the function

                      pianofire 1 Reply Last reply Reply Quote 0
                      • pianofire
                        pianofire Fuze Team @Mechanical last edited by pianofire

                        @Mechanical So variables can be local or global. As you say variables that are declared within a function are local to it and will cease to exist outside of the function. Variables declared outside of a function are global and they will persist even after the function has exited.

                        P 1 Reply Last reply Reply Quote 0
                        • P
                          petermeisenstein F @pianofire last edited by

                          @pianofire but with the next update there will changes right?

                          pianofire 1 Reply Last reply Reply Quote 0
                          • pianofire
                            pianofire Fuze Team @petermeisenstein last edited by

                            @petermeisenstein There will be a change to the way that parameters are passed to functions. Global and local variables will remain the same.

                            M 1 Reply Last reply Reply Quote 0
                            • M
                              Mechanical @pianofire last edited by

                              @pianofire sooo, practically I need to change Syntax when the new update rolls out? Or does it stay the same on the frontend?

                              pianofire 1 Reply Last reply Reply Quote 0
                              • pianofire
                                pianofire Fuze Team @Mechanical last edited by

                                @Mechanical There was some confusion about whether parameters were being passed to functions by reference or by value. To clarify the situation the default is now by value and if you want to pass by reference you will need to add "ref" in front of the parameter (from the next patch)

                                P 1 Reply Last reply Reply Quote 0
                                • P
                                  petermeisenstein F @pianofire last edited by

                                  @pianofire but it wont be possible for variables declared "new" in your function so a variable who is only declared inside your function

                                  pianofire 1 Reply Last reply Reply Quote 0
                                  • pianofire
                                    pianofire Fuze Team @petermeisenstein last edited by

                                    @petermeisenstein Sorry I don't understand the question

                                    P 1 Reply Last reply Reply Quote 0
                                    • P
                                      petermeisenstein F @pianofire last edited by

                                      @pianofire So here is an example

                                      function()
                                      my_variable=1
                                      return void

                                      Can i use my_variable outside this function

                                      pianofire 1 Reply Last reply Reply Quote 0
                                      • pianofire
                                        pianofire Fuze Team @petermeisenstein last edited by pianofire

                                        @petermeisenstein So if you declare the variable outside of the function it becomes global and can be used anywhere:

                                        int my_variable = 0
                                        
                                        function test()
                                          my_variable=1
                                        return void
                                        
                                        test()
                                        
                                        print(my_variable) // value will now be 1
                                        
                                        P 1 Reply Last reply Reply Quote 0
                                        • P
                                          petermeisenstein F @pianofire last edited by

                                          @pianofire Ok thanks

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post