PDA

View Full Version : Puzzled - a ZScript beginner question



Flycatcher
06-20-02, 03:52 PM
I've been trying my first stab at ZScripting today, starting logically enough with Davey's Lesson 1. I enjoyed the very clear tutorial and found the first exercise easy, but... then made the confidence-eroding mistake of going into experimental mode.
:(
As is my wont with any new programming language, I added a little extra practice by setting myself related problems that required dipping into the Reference Guide for a bit of extra information. So having successfully completed the complementary colour exercise, I tried a slightly more ambitious one on the colour wheel theme. The script below is supposed to display a button which when clicked displays a colour swatch in the script window comprising the current main colour and the other two triadic colours from the colour wheel (i.e. the additional two colours equidistant from the main colour and each other). The user is also supposed to be able to then change the main colour if he wishes, and press the button again to see the new triadic set, ad infinitum.

[PenMoveLeft]
[VarDef, r(3)]
[VarDef, g(3)]
[VarDef, b(3)]
[IButton, "Triadic Colours", "Show the triadic colours based on the current colour",
[VarSet, r(0), [IGet, Color:Red Component]]
[VarSet, g(0), [IGet, Color:Green Component]]
[VarSet, b(0), [IGet, Color:Blue Component]]
[VarSet, r(1), g(0)]
[VarSet, r(2), b(0)]
[VarSet, g(1), b(0)]
[VarSet, g(2), r(0)]
[VarSet, b(1), r(0)]
[VarSet, b(2), g(0)]
[PenMoveLeft]
[PenMove, 160]
[PenSetColor, r(0), g(0), b(0)]
[PaintRect, 20, 20]
[PenSetColor, r(1), g(1), b(1)]
[PaintRect, 20, 20]
[PenSetColor, r(2), g(2), b(2)]
[PaintRect, 20, 20]
, , , shift+alt+'T'
]

I know I could have made this shorter by not using array variables, but I thought it would give me practice with a few extra commands, and anyway makes it easier to see what is going on - never a bad thing in my experience. They, however, were not what gave me difficulties; displaying the results did. I have three problems with this script, the first two obviously closely related and possibly indicating something I don't know about the PaintRect command:

1. When the button is first pressed, the colour swatch appears, but only displays approximately the bottom quarter of the squares. However, if I then Alt-Tab to switch windows to my text editor then straight back again to ZBrush, the 20x20 squares are now displayed in full.

2. On changing the main colour and pressing again, either just the bottom quarter or so of the new swatch similarly appears (overwriting the bottom of the original swatch), or more often nothing appears to change at all until I leave the ZBrush window then return to it, when either way once again the new triadic swatch appears perfectly overwriting the previous version as intended.

3. Finally, my original intention had been to display the colour swatch just to the right of the button with the tops of the button and the swatch aligned. No combination of pen movements that I was able to come up with achieved this, hence I settled in the end for what you see here - a vertical displacement as well as a horizontal one.

Any help with either the strange screen-refresh problem or my failure to understand the pen movements properly will be greatly appreciated. I feel really stupid at having so many problems with such a simple script, but then again it is my first attempt so please be kind.

In case it matters, I'm on a PC running Windows 98 SE.

kaz-g
06-20-02, 04:45 PM
Hi Flycatcher,

Maybe you can use 'Section' instead of 'IButton' to fix your problem.

This technic was written on This thread (http://www.pixolator.com/zbc-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=003555) by Davey.
To Aurick: maybe above thread doesn't exist ZScript quick link. I think it is very important technic.It would be a good idea to add this to the links. If already exist, sorry. ;)

Please look into this.

I hope this helps you. :)

kaz-g

Flycatcher
06-20-02, 05:07 PM
Thanks for drawing my attention to that Kaz. :) I've had a look at the script, and yes it does seem that it should do the trick, albeit a more complicated solution than I had anticipated. I seem to have accidentally jumped ahead of myself on the learning curve here! :rolleyes:

However, I'm still slightly puzzled. In the original post (http://www.pixolator.com/zbc-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=003548) from JohnArtBox, hes says that "The PaintRect command does this when the zscript is initialised but because it cannot be used within an IButton does not update." I was unaware of this restriction, but it does not seem to be completely true because the screen does in fact reflect the changes after forcing it to refresh by switching to another window and back again. So the actual problem appears to be that the PaintRectdoeswork even inside an IButton, but that for some reason the screen requires forced refreshing to make this visible. Is there anyway to force a screen refresh from within ZScript? (I assume the answer is probably "no" and hence Davey's more complex method using Sections.)

I'm still no wiser about the third problem in my original post, though - how to get the rectangle to appear top-aligned with my IButton. :qu:

Muvlo
06-20-02, 05:12 PM
For question number three about moving the rectangles, did you try using negative numbers? For example, [PenMove,-20,-20] moves the pen left and up, but [PenMove,20,20] moves the pen right and down.

kaz-g
06-20-02, 05:13 PM
Hi Flycatcher,

One more,

You have to write 'PaintRect' command outside of the 'IButton'.
This also will sort out 3rd problem.

The refresh technic only affects to commands written as top-level command (not nested another command).

Top level commands are executed when,
1.Scroll ZScript window.
2.Resize ZScript window.
3.Expand/Collapse a section.
4.Change application task.
5.Load the ZScript.
6.(Maybe there are some other situation, but I don't know anymore) :)

[PenMoveLeft]
[VarDef, r(3)]
[VarDef, g(3)]
[VarDef, b(3)]

[SectionBegin,"",0,"Refresh",
[IUnpress,0]
][SectionEnd]

[IButton, "Triadic Colours", "Show the triadic colours based on the current colour",
[VarSet, r(0), [IGet, Color:Red Component]]
[VarSet, g(0), [IGet, Color:Green Component]]
[VarSet, b(0), [IGet, Color:Blue Component]]
[VarSet, r(1), g(0)]
[VarSet, r(2), b(0)]
[VarSet, g(1), b(0)]
[VarSet, g(2), r(0)]
[VarSet, b(1), r(0)]
[VarSet, b(2), g(0)]
[IPress,-1]
, , , shift+alt+'T'
]

[PenMoveLeft]
[PenMove, 160]
[PenSetColor, r(0), g(0), b(0)]
[PaintRect, 20, 20]
[PenSetColor, r(1), g(1), b(1)]
[PaintRect, 20, 20]
[PenSetColor, r(2), g(2), b(2)]
[PaintRect, 20, 20]

I hope this helps you.

kaz-g

Flycatcher
06-20-02, 05:18 PM
Hi Muvlo - Thanks, but yes I tried negative values but couldn't find one that put it in the right place both on the first click of the IButton, and also on the second. Maybe it's related to the info that Kaz has given me on my misuse of the PaintRec command inside the IButton. I'll have another try tomorrow - bed is calling now (01:30 here). ;)

Flycatcher
06-20-02, 05:23 PM
Hi again Kaz - Great! That helps a lot - I'm much clearer now. These are the sort of problems you get from trying to jump ahead too quickly. :o

Thank you for your assistance.

:tu: :) :tu:

kaz-g
06-20-02, 05:24 PM
Hi Flycatcher,

You're welcome.
Good night. :)

kaz-g

aurick
06-20-02, 05:47 PM
Thanks for the heads up on the ZCoders tutorial. I've now added it to the QuickLinks. :tu:

kaz-g
06-20-02, 06:09 PM
Hi aurick,

Wow, quick action!! :tu: :tu:

Thanks. ;)

kaz-g

Muvlo
06-20-02, 07:13 PM
Actually Aurick, the link is already in your quicklinks, listed under "How can I make a dynamically updating window in the ZScript panel?"

banez
06-20-02, 08:00 PM
look at Material Maker (2) http://www27.brinkster.com/ezbrush/mainTools.html
there is a Color Box and the COLOR DIF button will change the color inside the box i notice on yours if you click inside the tutorial window your color box will dissapear.
davey posted a code a while back but the only way i can see the color box change is to click and shake the tutoral window.
mine works fine check it out.
im not sure what your trying can you re explain and keep it short i was confussed.
your ALT+SHIFT+T is activating the Tool Pallete

banez
06-20-02, 08:29 PM
use

[IPress,-1]
,,,SHIFT+'t'
]

kaz-g
06-20-02, 08:35 PM
Hi Muvlo,

You are right.
The link has already existed.
I couldn't just find it :o

Aurick, sorry to bother you.

kaz-g

banez
06-20-02, 09:01 PM
i can't Find it Were is the Link ?
never mind i just found it
:confused:

Flycatcher
06-21-02, 05:45 PM
Hi EZ - The essential part of what I was trying to do was create three rectangles in the tutorial window whose colour I could update when the button was pressed. The actual colour changes bit worked first time; it was just displaying the results that gave me problems.

As a total beginner with ZScript (only my second little practice exercise), I was unaware that I should not use PaintRect inside an IButton. This was the root of all my problems.

I already had your script downloaded, and have now had a quick look at the relevant section - very helpful, thank you. :tu:

Thanks to Kaz and yourself, I now have the answers I needed and learned far more than I expected from what started off as a seemingly trivial little exercise.

PS I had noticed the disappearing box when I clicked in the tutorial window at one point during testing, but thought that had gone away. I was mistaken. I'm afraid I hadn't even got around to trying the short-cut key, so hadn't noticed the other symptom you described. :o