Putting loop in different procedures of code
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Putting loop in different procedures of code
Hi i have a question about creating a loop that starts and ends in different procedures of code
I am following Pseudocode that says i
1. Start loop
2.
3.
4.
5. End loop
Each step of pseudocode must be a different procedure
ie on initialise
end initialise
Here is the code and the error message displayed
Can you please let me know what i have done wrong or how to do this
I am following Pseudocode that says i
1. Start loop
2.
3.
4.
5. End loop
Each step of pseudocode must be a different procedure
ie on initialise
end initialise
Here is the code and the error message displayed
Can you please let me know what i have done wrong or how to do this
Re: Putting loop in different procedures of code
I really don't understand what it is that you are trying to do. I don't see anything in your pseudocode that suggests you need a loop that starts in one handler and ends in another. This is something you cannot do given the structures you suggest in your pseudocode.
You can achieve the same effect with different commands, like "send <handlername>" but I am not at all sure that you need such a structure. I can't see what you are trying to achieve with this.
For a basic loop, the syntax iswhere tLoop is a variable name. "loop" is not a part of the "repeat" command syntax - it is a given that you are looping, and the "with" form requires you to specify a variable which is incremented each iteration of the loop. (As opposed to the "repeat for each" form of the repeat loop. )
Could you explain a bit more what it is that you are trying to do with this?
You can achieve the same effect with different commands, like "send <handlername>" but I am not at all sure that you need such a structure. I can't see what you are trying to achieve with this.
For a basic loop, the syntax is
Code: Select all
repeat with tLoop = 1 to 5
Could you explain a bit more what it is that you are trying to do with this?
Re: Putting loop in different procedures of code
I'm with SparkOut on this, for starters, you can't start a repeat loop in one handler and end it elsewhere.
What you *could* do, though, is start a repeat loop and have it call all your handlers, but that would be pointless as it would be a 1 time loop, so it would be more efficient to just call the handlers one after the other.
The only other thing I'd add is this sounds an awful lot like a homework assignment
What you *could* do, though, is start a repeat loop and have it call all your handlers, but that would be pointless as it would be a 1 time loop, so it would be more efficient to just call the handlers one after the other.
The only other thing I'd add is this sounds an awful lot like a homework assignment

Last edited by bogs on Sat Feb 16, 2019 1:06 pm, edited 1 time in total.

Re: Putting loop in different procedures of code
Hi mbell03,
welcome to the forum!
I HIGHLY recommend to check one or two or all of these stacks to get the very basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
welcome to the forum!
I HIGHLY recommend to check one or two or all of these stacks to get the very basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: Putting loop in different procedures of code
Hi.
Or better, give an actual example of code, even if that code doesn't actually do anything, but is only indicative of your intent, something like:
Then we can comment on how you might build a handler that actually does some work.
Craig Newman
Or better, give an actual example of code, even if that code doesn't actually do anything, but is only indicative of your intent, something like:
Code: Select all
on mouseUp
doThis
doThat
repeat with y = 1 to 5
put y into temp
end repeat
doSomethingElse
end mouseUp
Craig Newman
Re: Putting loop in different procedures of code
You know, as I was thinking about this, it occurred to me they might not be talking about an actual loop, but merely passing a result along or having one handler call another. That is certainly possible to do and would make sense.

Re: Putting loop in different procedures of code
@Bogs.
The example does say "repeat", so I think that is a given. I assume the question refers to the ability in general to call command and function handlers from within other handlers, and to do so within a repeat is just a particular example.
@ mbell03:
In a button script, does this help?
Pretty silly, eh? But I wanted you to see how values are passed and acted on within separate handlers.
Craig Newman
The example does say "repeat", so I think that is a given. I assume the question refers to the ability in general to call command and function handlers from within other handlers, and to do so within a repeat is just a particular example.
@ mbell03:
In a button script, does this help?
Code: Select all
on mouseUp
repeat with y = 1 to 3
doubleNumber y
tripleNumber y
end repeat
end mouseUp
on doubleNumber var
answer "Doubling" && var && "gives" && var * 2
end doubleNumber
on tripleNumber var
answer "Tripling" && var && "gives" && var * 3
end tripleNumber
Craig Newman
Re: Putting loop in different procedures of code
Hi the reason i am specific about the pseudocode steps being the same as a handler as this is a school project and we have been told that is what it means. If this isnt possible thats fine but i wasnt sure if there was a way to do it that i didnt know about.SparkOut wrote: ↑Fri Feb 15, 2019 11:40 pmI really don't understand what it is that you are trying to do. I don't see anything in your pseudocode that suggests you need a loop that starts in one handler and ends in another. This is something you cannot do given the structures you suggest in your pseudocode.
You can achieve the same effect with different commands, like "send <handlername>" but I am not at all sure that you need such a structure. I can't see what you are trying to achieve with this.
For a basic loop, the syntax iswhere tLoop is a variable name. "loop" is not a part of the "repeat" command syntax - it is a given that you are looping, and the "with" form requires you to specify a variable which is incremented each iteration of the loop. (As opposed to the "repeat for each" form of the repeat loop. )Code: Select all
repeat with tLoop = 1 to 5
Could you explain a bit more what it is that you are trying to do with this?
Basically the program spec wants to find generate a username and at the begining you are asked how many usernames you need that is why i need the loop so the program will repeat all the steps of generating the username for the amount of usernames needed.
Thanks for your assistance
Re: Putting loop in different procedures of code
Unfortunately not the loop i need to create needs to be looped an amount of times entered by the user so i am unable to do that there as i get error messagesdunbarx wrote: ↑Sat Feb 16, 2019 6:15 pm@Bogs.
The example does say "repeat", so I think that is a given. I assume the question refers to the ability in general to call command and function handlers from within other handlers, and to do so within a repeat is just a particular example.
@ mbell03:
In a button script, does this help?Pretty silly, eh? But I wanted you to see how values are passed and acted on within separate handlers.Code: Select all
on mouseUp repeat with y = 1 to 3 doubleNumber y tripleNumber y end repeat end mouseUp on doubleNumber var answer "Doubling" && var && "gives" && var * 2 end doubleNumber on tripleNumber var answer "Tripling" && var && "gives" && var * 3 end tripleNumber
Craig Newman
Re: Putting loop in different procedures of code
Yah, that would make sense, especially with the last 2 posts. I just know you can't start a loop in one handler and end it somewhere else.
The loop Craig showed you was to give you an example of how to do a loop and have it call other handlers. You would have to modify it to suit your additional information, but to break it down it would be modified something like this -
Code: Select all
/* you get your input from the user, probably in an ask dialog or field.
Let us assume your user enters 5 into a field, and you have a button
below that to start the routine. */
on mouseUp
put field "userInput" into tNum
repeat with y = 1 to tNum
handlerOne
handlerTwo
handlerThree
handlerFour
handlerFive
end repeat
end mouseUp
on handlerOne
//your code here...
end handlerOne
on handlerTwo
//your code here...
end handlerTwo
// etc etc...

Re: Putting loop in different procedures of code
Ok so from this example is the code for the user input before the onmouseup ?
Re: Putting loop in different procedures of code
No, everything between /* and */ is a comment.
Do yourself and us a favour and read up this link:
viewtopic.php?f=7&t=32177#p176592
Currently we are apparently not talking the same language, which makes it hard to communicate correctly.
Do yourself and us a favour and read up this link:
viewtopic.php?f=7&t=32177#p176592
Currently we are apparently not talking the same language, which makes it hard to communicate correctly.
Re: Putting loop in different procedures of code
Klaus has a point there, and he already explained that the top text is a comment
There is no code needed for the field "userInput", everything there happens in the button script.
See if this hits closer to what your trying for.

There is no code needed for the field "userInput", everything there happens in the button script.
See if this hits closer to what your trying for.

Re: Putting loop in different procedures of code
Thanks for everyones help i have figured that out annoyingly there must be errors with other parts of my code but an error that doesnt make sense to me is a bad command error for using indentation ??
Re: Putting loop in different procedures of code
If you can post the actual error and the code you are using for the indentation, we might be able to tell you what the problem is 

