Post by tsh73 on Nov 17, 2023 19:11:31 GMT
Two graphicbox tips.
Accidentally found. Seems to me NOT obvious, at all.
Tip #1
Sometimes it looks worthy to combine long list of graphic commands into one long string of commands, delimited by ( ; ).
But sometimes it does not work.
I know printing (#gr "\some text") cannot be chained that way
But I just stumbled on another exception:
If your long string of commands contains POSXY, getting current coordinates
Then variables do not get changed until after whole long string will be processed.
That means you cannot get current position,
and use it in the long string of commands after POSXY
- they'll still have old values.
Tip #2
MouseX, MouseY is global.
So you do not need to pass them into sub/function but can use right away.
I guess might get handy.
Accidentally found. Seems to me NOT obvious, at all.
Tip #1
Sometimes it looks worthy to combine long list of graphic commands into one long string of commands, delimited by ( ; ).
But sometimes it does not work.
I know printing (#gr "\some text") cannot be chained that way
But I just stumbled on another exception:
If your long string of commands contains POSXY, getting current coordinates
Then variables do not get changed until after whole long string will be processed.
That means you cannot get current position,
and use it in the long string of commands after POSXY
- they'll still have old values.
Tip #2
MouseX, MouseY is global.
So you do not need to pass them into sub/function but can use right away.
I guess might get handy.
nomainwin
open "Read, then do click" for graphics_nsb as #gr
#gr "trapclose [quit]"
#gr "down; turn 90" 'right
x=50:y=40
#gr "place 100 50"
#gr "\\Drawing in several statements"
#gr "\posxy registered, RED dot"
#gr "\at the end of the line"
#gr "go 50"
#gr "posxy x y"
#gr "size 5"
#gr "color red"
#gr "set ";x;" ";y
'reset
#gr "size 1"
#gr "color black"
x=50:y=140
#gr "place 100 150"
#gr "\\Drawing as a single long line"
#gr "\posxy NOT registered"
#gr "\while drawing CYAN dot"
#gr "\But after, GREEN dot gets right"
#gr "go 50; posxy x y; size 5; color cyan; set ";x;" ";y
#gr "color green; set ";x;" ";y
#gr "size 1"
#gr "color black"
#gr "flush"
#gr "when leftButtonUp [click]"
wait
[quit]
close #gr
end
[click]
call testSub
wait
sub testSub 'the point of this sub is to show that MouseX, MouseY is global
#gr "place 0 0" 'watch top left corner
#gr "\\ "
#gr "place 0 0"
#gr "\\"; MouseX;" ";MouseY;" MouseX, MouseY is global!"
end sub