Learning Ruby by Writing a Working Shell?
-
Hi Devs,
A while back, I tried to start working on a script to create spot elevation markers here http://sketchucation.com/forums/viewtopic.php?f=180&t=51558, which turned out to be far too ambitious for my limited knowledge of ruby. So here's what I'd figuring I'll start doing to write my plugin(s).
I'm going to start by creating the menus, the organization, and extension information, and get that working in SketchUp first, essentially just as a proof of concept. If I can just get the plugin working as a working "shell" as it were, I can then replace the methods calling Messages Boxes with actual working methods.
So as my first question: What is causing the script to only return "You clicked YES!" instead of the expected response? [Line 24-29]
Here's the GIT for those of you that want it:https://github.com/mattgordon320/GB_Tools.git
Let me know what you think and that'll get me a start!
Thanks gents!
-Matt
-
It could be the if statement your using assignment instead of comparison ?
= to == -
As has been said - your tests do not use the correct syntax.
Using
if x = 6
is ALWAYS going to return true... because using that syntax you have simply set x to be 6: the = 'assigns' values.
Usingif x **==** 6
will only return true if x IS 6: the == 'compares' values. -
In order to avoid using assignment rather than comparison, software devs often put the constant on the left side of the expression because it cannot be "assigned to" (properly, its not an "lvalue") so you avoid this common typo.
ie write it as:
if 6 == x
whereas (mistakenly) typing:
if 6 = x
will cause your programming language to bark at you.
-
Ah, I see. Fixed. I've definitely got more digging and learning to do. I don't understand the ruby syntax very well yet. Thanks guys! I'll post whenever I update more/have another question.
-
Read the Pick-Axe book.
-
Pick Axe book...you mean the Ruby Newbie's Guide....?
-
-
Thanks Dan, coincidentally I just bought the pick axe. I'll be hammering though my way through that starting this weekend
Sent from my Galaxy Nexus using Tapatalk
Advertisement