adding the following blockspecs:
('%v' r reportVar: '') - ('set %v to %s' - setVar:to: '' '0') ('change %v by %n' - changeVar:by: '' 1)
under variables causes the error:
How do I fix this? I haven't edited my translator scripts, and only this bit causes the error.
Last edited by Interest (2012-12-25 22:10:46)
Offline
hmm... it's probably something really obvious, but I don't see the problem since I too use a similar block spec. If you're sure that's the stuff that's causing the error, try replacing the empty strings '' with a dash -
Offline
doesn't work. It probably has something to do with
defaultArgs:
but I don't know what it might be
Offline
This is often the cause of a variable being nil when it shouldn't be. In this case, it is calling the defaultArgs function on an object that doesn't have one. In the debugger, you can look through all of the functions and find what triggered it.
Offline
Error: an attempt was made to send the given message but the receiver does not understand this message. This message is sent by the virtual machine when a message is sent to an object that does not define a method for the message selector."
"Example: 3 width
Offline
Here's how I would solve that:
I haven't looked at the code for #addGenericVariableBlocksTo:x:y:, but I can tell two things (of significance here) from that debugtrace:
1) The message #defaultArgs: was sent to an object that didn't understand it.
2) The object which did not understand it was an instance of Symbol.
Since adding those block specs seemed to cause the error, the Symbol instance which didn't understand #defaultArgs: was probably something in them (or something derived from them). Let's start with the simplest case: the Symbol instance was somewhere inside of those block specs. Scanning through, I see four symbol instances. I'm pretty sure those are valid blocks, so I can eliminate the three specifying the type of each block. That leaves the #- used as a separator. I'm pretty sure that this caused the error.
Time look a the code. I click "Debug" in the error window and get the expanded debugger. I select #addGenericVariableBlocksTo:x:y: from the list, and the editor shows me the error occurred in the first #do: loop. It looks like #blocksFor: is returning the separator symbol unchanged; when it gets passed to the block, it's calling #defaultArgs: and throwing the error.
I know that I've see #- used for separators before, so I'm going to look at how #blocksFor: is used elsewhere and see what's done there. I highlight it (double-click) and browse its senders (n). #viewerPageForCategory: sounds good, so I look through its source. In its #do: loop, it checks for and inserts separators for two symbols: #- for a half space and #~ for a full space. #viewerPageForCategory:'s loop is doing layout like #addGenericVariableBlocksTo:x:y:'s second #do: loop, so I copy that section there (and rename the variables).
That still won't solve the error, though, which was occurring in the first loop. #defaultArgs: just sets the blocks' default arguments; since separators don't have default arguments, I can simply add an #isKindOf: check around that statement. I accept my changes right from the debugger, and refresh the palette. Sure enough, the error's gone.
The final source of #addGenericVariableBlocksTo:x:y: looks like this for me: (yours will probably be different because I assume you're doing this in a mod)
addGenericVariableBlocksTo: page x: x y: startY
"Add the generic variable blocks to the given page starting at the given y offset. Answer the new y."
| y vName stage block varBlocks |
y _ startY.
"…"
(self blocksFor: 'variables') do: [:b |
(b isKindOf: Symbol) ifFalse: [b defaultArgs: (Array with: vName)].
varBlocks add: b].
varBlocks do: [:b |
(b = #-) | (b = #~)
ifTrue: [
(b = #-) ifTrue: [y _ y + 15]. "insert a full space"
(b = #~) ifTrue: [y _ y + 5]] "insert a half space"
ifFalse: [
b color: self variableBlockColor.
page addMorph: (b position: x@y).
y _ b bottom + 3]].
^ y
EDIT: For future reference, the things you added aren't a script; they're a couple of elements in the blockSpecs array.
EDIT2: I copied and pasted to make this post shorter. In production code, you should abstract that into another method (it's also used in #viewerPageForMotion and possibly some others; I didn't check).
Last edited by nXIII (2012-12-24 23:13:32)
Offline
doesn't work, creates error:
here is the image: http://bit.ly/WFanpS
Offline
There's a comment in the middle of that snippet at the end: "…". An ellipsis indicates truncation. I truncated it for three reasons:
1) The method source was really long, and my post was already in danger of becoming a short novel.
2) My method source was based on the original ScratchSourceCode1.4 image. I assumed you had modified yours, so I just showed the relevant parts.
3) I didn't want you to copy-paste it. This is a trivial problem; I could have solved it in under two minutes and just posted the code. Instead, I posted a description of how I solved it in the hopes that next time you had a problem like this, you'd emulate that process and be able to debug something without asking about it on the forums.
If you read my post, you'll probably be able to integrate that snippet at the end into your own method's source code. If you're still not sure, I'd be happy to add screenshots or help you in some other way. I'm not going to just paste in code, though.
Last edited by nXIII (2012-12-25 23:56:26)
Offline
1. yes, the #- separator caused the error: removing it solved the problem
2. this is the code, but I don't see the problem with defaultArgs:
->
3. it seems to have disabled all my stage watchers except the normal variable ones.
updated image: http://bit.ly/WFanpS
Offline
doesn't work, if you look at my updated image fixing that causes a chain reaction, from color: to variableBlockColor
Offline