Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Question

5 answers to this question

Recommended Posts

  • 0

Darthhose,  if you're using goto, then you might want to consider rethinking the code...

 

i appreciate, however, that this isn't always obvious to a beginner... if you have an example piece of code which you think needs goto, post it here and i'll give you tips on how to avoid goto altogether... 

 

i've not used goto in code for over 20 years [ from using VB3 in banking systems development ] and i can't say i've ever missed it :)

 

it's not that it doesn't have a purpose if the code is a "very quick hack" - but for better structured, functional and reusable code, it's evil and should be avoided... 

[ i didn't even know lua was evil enough to have the statement in its syntax until i saw a similar post re: goto last night here ] 

 

i'm not saying this with any arrogance, i'm just saying - if you're learning to code, best to not even know that goto exists, it'll work out better for you in the end, and i'm happy to help with anything you think that needs it... just post an example here, and i'll reply with an alternative - and an explaination...

Link to post
Share on other sites
  • 0

i know this is an old thread.
but its actually exactly what i'm looking for

i have the following code

local function timer()
    seconds = 0 
    while true do
        ::startover::
        if reactor.getActive() == true then
            while true do
                seconds = seconds + 1
                if seconds == 60 then
                    minutes + 1
                    seconds = 0
                end
                if minutes == 60 then
                    hours + 1
                    minutes = 0
                end
                center(2,"Time Running: "hours..":"..minutes..":"..seconds)
                sleep(1)
                if reactor.getActive == false then
                    goto startover
                end
            end
        end
    end
end

But as Ingie says, it should be avoided if possible (first time i actually want to use it, as i dont see another way around atm.. 
but might just be me.. 

but the code should be pretty self explanitory, when it comes to what it does.

it should be noted, that i HAVENT tested the code ingame yet, as i'm writing it while at work. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.