goto (runs and hides)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
goto (runs and hides)
I know using a goto command in some languages just shows poor code layout. i remember it as far back as commodore 64 and 128 days. Does this exist in livecode?
Re: goto (runs and hides)
In basic, "goTo" allows a subroutine to be executed. The calling "handler" pauses, and the designated routine starts. Control reverts to the calling handler upon completion.
In LC, the same concept exists, though mightily enhanced, and the methods to call the "subroutine" are varied. Knowing the hierarchy, you can:
or you could:
or:
or:
or:
or:
or:
LC wins hands down, in flexibility, power and fun.
Craig Newman
In LC, the same concept exists, though mightily enhanced, and the methods to call the "subroutine" are varied. Knowing the hierarchy, you can:
Code: Select all
yourCode
yourCode
subRoutine --This is the, er, "subroutine"
yourCode
yourCode
Code: Select all
yourCode
yourCode
send "subroutine" to yourDestinationObject --This has additional power
yourCode
yourCode
Code: Select all
yourCode
yourCode
do "subRoutine" --This has considerable additional power
yourCode
yourCode
Code: Select all
yourCode
yourCode
send "subRoutine" && paramLlist to anywhereAtAllOnThePlanet --This has even more and better and just darned extra considerable additional power
yourCode
yourCode
or:
or:
LC wins hands down, in flexibility, power and fun.
Craig Newman
Re: goto (runs and hides)
i cant find anything on subroutine in the dictionary and from what i see by googling it it has something to do with variables and from the way your describing it it doings like a "Command" or "function". i was thinking of using a goto command like being in an if and then jumping a section of code by lets say going to line 80 of the code. on the commodore 64 it allowed you to jump forward or backwards in your code
Re: goto (runs and hides)
Nope. I used to use those for clean up and error recovery in earlier HLLs. You want to create a label somewhere in the routine and jump to it from various other places, which LC can't do. Expanding on Craig's answer, LC has lots of flexibility for this, and one mechanism would be to create a separate recovery subroutine that your main routine can start up and exit (in pseudocode, off the top of my head):
on mySub
doStuff
if exceptionDiscovered then
send "myCleanUp" && someErrorInformation to me in 0 milliseconds
exit to top
end if
doSomeMoreStuff
if exceptionDiscovered then
send "myCleanUp" && someErrorInformation to me in 0 milliseconds
exit to top
end if
end mySub
on myCleanUp pTheErrorCode
doErrorLoggingStuff
undoStuff
end myCleanUp
on mySub
doStuff
if exceptionDiscovered then
send "myCleanUp" && someErrorInformation to me in 0 milliseconds
exit to top
end if
doSomeMoreStuff
if exceptionDiscovered then
send "myCleanUp" && someErrorInformation to me in 0 milliseconds
exit to top
end if
end mySub
on myCleanUp pTheErrorCode
doErrorLoggingStuff
undoStuff
end myCleanUp
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: goto (runs and hides)
Livecode uses discrete, named handler and function routines exclusively, These are accessed by, and one might consider their "address" to be referenced by, those names . This is basic stuff, and part of what you need to know at the foundation of the language. Consider this, which only touches the surface of LC capabilities. In a new card with one button and one field, in the button script:
Now this:
Why call other handlers or functions at all? Couldn't the action of each of those "mouseUp" handlers be implemented directly? This is the stuff of the first 50 hours of getting to know the structure of LC. If you are familiar with the "goto" command, you will pick up the nature and value of the message paradigm right away, and be blown away. Go through the tutorials, practice, and write back when you are stuck. But you must, simply must get stuck first.
Craig Newman
Code: Select all
on mouseUp
put random(9) into field 1
checkTheField
end mouseUp
on checkTheField
if fld 1 > 5 then answer "Big Number in Field"
end checkTheField
Code: Select all
on mouseUp
put random(9) into field 1
answer checkTheField(field 1)
end mouseUp
function checkTheField theValue
if theValue > 5 then return "Big Number in Field"
end checkTheField
Craig Newman
Re: goto (runs and hides)
instead of
on checkTheField
is usually write
command checkTheField
which i think is the exact same thing just that "on" is shorter to type than "command"... then again if you use "on" can you pass it variables like command can do?
i wasnt really asking about goto as a serious thing i wanted to use. I found an old notebook i had written some C64 game code in and goto was one of the commands i used and i dont think ive seen it anywhere else since then, i think PHP has it but ive never used it there and i saw people saying bad things about it

on checkTheField
is usually write
command checkTheField
which i think is the exact same thing just that "on" is shorter to type than "command"... then again if you use "on" can you pass it variables like command can do?
i wasnt really asking about goto as a serious thing i wanted to use. I found an old notebook i had written some C64 game code in and goto was one of the commands i used and i dont think ive seen it anywhere else since then, i think PHP has it but ive never used it there and i saw people saying bad things about it

Re: goto (runs and hides)
The two are synonyms. I use "on" because I always have.
They are control structures that define a message handler, and are the basic building block of LC. Parameters may be attached as required. These are evaluated before they are passed, and may be by value or by reference. Very powerful tools.
on mouseUp
doSomething the long date,myVariable,random(99),theSkyIsTheLimit
end mouseUp
Wikipedia has a great discussion of "goto"
Craig
They are control structures that define a message handler, and are the basic building block of LC. Parameters may be attached as required. These are evaluated before they are passed, and may be by value or by reference. Very powerful tools.
on mouseUp
doSomething the long date,myVariable,random(99),theSkyIsTheLimit
end mouseUp
Wikipedia has a great discussion of "goto"
Craig