This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-05 06:41:50

nsmbodabor
New Scratcher
Registered: 2011-07-19
Posts: 37

Changing 'nil' to blank

Okay, So I have the following block that I've created;

Blockspec:

Code:

('Right Click Menu %s %s %s'    r    rightButtonMenu2:opt2:opt3: 'opt1' 'opt2' 'opt3')

Method:

Code:

rightButtonMenu2: t1 opt2: t2 opt3: t3
    | menu |
    menu _ CustomMenu new.
    menu add: t1 action: t1.
    menu add: t2 action: t2.
    menu add: t3 action: t3.
    ^ menu startUp: #test

My question is, how do I make the reporter report a blank string instead of 'nil' when the user clicks off the menu without selecting an option?

Offline

 

#2 2013-01-05 07:22:02

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Changing 'nil' to blank

I haven't modded Scratch in a while, but something like this might work:

Code:

test isNil
    ifTrue: [^ '']
    ifFalse: [^ test].

Replace "test" with the variable that contains the menu item that was clicked.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#3 2013-01-05 09:05:31

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Changing 'nil' to blank

Returning from blocks is no fun!  tongue

| menu result |
"..."
result := menu startUp: #test.
^ result ifNil: [''] ifNotNil: [result]

Last edited by nXIII (2013-01-05 09:12:49)


nXIII

Offline

 

#4 2013-01-05 13:05:33

nsmbodabor
New Scratcher
Registered: 2011-07-19
Posts: 37

Re: Changing 'nil' to blank

nathanprocks wrote:

I haven't modded Scratch in a while, but something like this might work:

Code:

test isNil
    ifTrue: [^ '']
    ifFalse: [^ test].

Replace "test" with the variable that contains the menu item that was clicked.

This might sound silly, but how do I set each menu option to define said variable?

Offline

 

#5 2013-01-05 20:13:12

nsmbodabor
New Scratcher
Registered: 2011-07-19
Posts: 37

Re: Changing 'nil' to blank

^Bump

Offline

 

#6 2013-01-06 07:51:28

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Changing 'nil' to blank

nsmbodabor wrote:

^Bump

nXIII answered your question. Here's the code pieced together:

Code:

rightButtonMenu2: t1 opt2: t2 opt3: t3
    | menu result |
    menu _ CustomMenu new.
    menu add: t1 action: t1.
    menu add: t2 action: t2.
    menu add: t3 action: t3.
    result _ menu startUp: #test.
    ^ result ifNil: [''] ifNotNil: [result]

Offline

 

Board footer