Inputbox Hamlet(to do or not todo)
-
Hi! Im doing a simple inputbox for this plugin.
http://forums.sketchucation.com/viewtopic.php?f=180&t=38481It's all TIG's (made in 30 min!)script. I will just have to add prompts for 3 values. Angle, spacing and units.
This is what I've got so far(It doesent refer to any values in the script yet).promts=["Angle (deg)", "Spacing", "Units"] defaults=["45", "20", ".cm"] list = ["", "", ".cm|.inches"] input =UI.inputbox promts, defaults, list, "Hatchfaces"I though it would be a simple task, but scanning through this forum there seams to be different opinions for what is correct and non correct constructions for UI.
Since this plugin will hatch faces, I thought putting a context-menu would be a good choice, followed by an inputbox prompt. However reading up a bit in here rmb click menus can be hazardous!??
And The Use of globals versus instance-varibles is confusing as well.
It's all a bit confusing to me, any tips would be very welcome. -
@angle=45.0 if not @angle # remembered if set this session @spacing=20.to_l if not @spacing # remembered if set this session prompts=["Angle(deg); ", "Spacing; "] values=[@angle, @spacing] title = "Hatchfaces Parameters" results = UI.inputbox(prompts, values, title) return nil if not results # i.e. the user canceled @angle=results[0] @spacing=results[1]This initially sets the 'angle' as a float, so it's expecting a float input so 45 or 22.5 will work, use
angle.degreeswhen using it later. It initially sets the 'spacing' as a 'length', so now like in the VCB the user can type in 20 [i.e. in current units] or 20cm or 200mm or 8" etc and it'll work OK with that - so no need for a dropdown list for setting these units... The spacing should be usable directly in your code without recasting its 'type' etc...
By using @ variables they will be remembered between uses in that session, when set inside a method, if it's inside a class use @@ variables as these persist across instances... [tip: declare the @@s within the class itself and use them in the methods as needed] Avoid global $ variables that can clash with other's coding as they are accessible to everything! ... BY using @ or [@@] then if the spacing is changed the next time you use the tool in that SUp session its dialog will show the last used angle/spacing rather than the defaults. -
Great! That makes things a lot clearer.
@unknownuser said:
Avoid global $ variables that can clash with other's coding as they are accessible to everything!
Thats especially the thing I was not sure about about. The last thing I wanna do is barge in here ruin everyones scripts..
Thanks a lot!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement