Outside the Mainloop


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73

    Default Outside the Mainloop

    First post - first program - I want to initialize some variables before the mainloop executes and have subroutines below the mainloop controlled by gosubs within the mainloop. The problem I've been seeing is the gosubs seems to execute without being called, for example a initialize the variables sub routine, like the program kept going instead of returning to the top of the mainloop. Do I need an "end" after goto mainloop?

    for example

    gosub init:

    MAINLOOP:
    if x = 2 then
    gosub dothis
    endif

    goto mainloop

    dothis:
    program
    return

    init:
    x = 1
    return

    I've seen the dothis sub routine get executed without gosub being executed...like the program just keeps going past the goto mainloop command - (crude example of my real program)

    I'm wondering if I'm missing a golden rule of keeping my program flow within the mainloop.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,531


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    Hi,
    Except for the colon in the line GOSUB Init: I don't see any issues with this piece of code. Make sure ALL subroutines ends with a RETURN. If you GOTO something FROM a subroutine then makes sure THAT piece of code ends with a RETURN. That's all the advice I can give you ATM.

    You'd be much better helped if you boil down your ACTUAL code to something small that still shows the error and post that.

    /Henrik.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,662


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    I used to write like you, except with the END as commented by Henrik.

    I have since changed to how I've seen countless examples here:

    Code:
    Define variables and stuff
    
    GOTO ProgramStart
    
    Subroutine1:
      bla bla
    RETURN
    
    ProgramStart:
      bla bla
      GOSUB Subroutine1
      GOTO ProgramStart
    END
    Your code "should" work. But I've never had a freaky situation by coding like this yet.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    GOSUB init not GOSUB init: (which would then be a label)
    MAINLOOP and mainloop are different things.

    Post your actual code and we will help you find the other (likely) typos.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,531


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    MAINLOOP and mainloop are different things
    No, they're not in this case. PBP is not case sensitive.

    /Henrik.

  6. #6
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    ok - thanks - I will... I'm currently trying to HPWM a set of LEDs with a 12F683 next so I'll give that shot. I havea degree in CS - JAVA and C++, but haven't used it since college. I'm 60 years old this year - not kidding.. never too late.

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    I stand corrected - labels are not case sensitive. Most other things are, however.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts