Hi all,
Since I've started messing around with the smalltalk code, I think I've developed a small understanding of how to make blocks, which I know isn't much, but I've heard other people ask this question too, so thought I would post a thread for it.
how do you get a C block to do something after the contents has been run? Specifically, I want to write text to a file once a loop starts and again when the loop ends so that rather than a block called <html> with the code
self writeText: '<html>' toFile: 'C:\Program Files\output\output.html'
and a second block called <html /> with the code
self writeText: '<html />' toFile: 'C:\Program Files\output\output.html'
I can just have a loop block that writes the first message at the start, and the second when the loop finishes. Html is just an example, I plan to use it to create blocks for programming microships, but you get the idea
any thoughts as to how this is done? Is it possible in Panther?
Offline
| block args |
block _ stackFrame expression.
args _ stackFrame arguments.
(args size = 1)
ifFalse: [
writeToFile: '<html>'.
self pushStackFrame: (ScratchStackFrame new expression: (block firstBlockList)).
stackFrame addArgument: 'temp'.]
ifTrue: [
writeToFile: '</html>'.
self popStackFrame.]
Replace writeToFile: with your file writing method.
(This works, I used it in my mod of Web Blox)
Offline
TheSuccessor wrote:
| block args |
block _ stackFrame expression.
args _ stackFrame arguments.
(args size = 1)
ifFalse: [
writeToFile: '<html>'.
self pushStackFrame: (ScratchStackFrame new expression: (block firstBlockList)).
stackFrame addArgument: 'temp'.]
ifTrue: [
writeToFile: '</html>'.
self popStackFrame.]
Replace writeToFile: with your file writing method.
(This works, I used it in my mod of Web Blox)
So your modding web blox
. Feel free to but please give credit.
Offline
thanks! One problem, I tried it in Panther and it failed. (as a custom block)
here's my code:
| block args |
block _ stackFrame expression.
args _ stackFrame arguments.
(args size = 1)
ifFalse: [
writeText: 'if ', t1, 'then','
' ToFile: 'picaxe out.bas'.
self pushStackFrame: (ScratchStackFrame new expression: (block firstBlockList)).
stackFrame addArgument: 'temp'.]
ifTrue: [
writeText: 'endif'
' ToFile: 'picaxe out.bas'.
self popStackFrame.]have I made a mistake?
Offline
Oh. It won't work in CYOB I don't think, as it runs in Scratch-Execution Engine => ScratchThread, where the execution of blocks is actually done. This is where all C blocks have their code as they tend to affect the way the script runs.
Offline