If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Ruby nuby needs help
4 posts
• Page 1 of 1
Ruby nuby needs help
I wrote a Ruby module to replace some green math just to learn a bit... after discovering 1/12 = 0 but 1.0/12 = 0.083333333 things went more or less as expected.
But when I reopened the schematic it was flagging a Ruby error... I couldn't figure it out as it looked OK and had been working when I saved... then I discovered if it clicked on each of the inputs it would resolve the error...
Here's the code the module contains:
Can anyone sort me out on this?
But when I reopened the schematic it was flagging a Ruby error... I couldn't figure it out as it looked OK and had been working when I saved... then I discovered if it clicked on each of the inputs it would resolve the error...
Here's the code the module contains:
- Code: Select all
def _Nx12thRoot2Inv(x)
1.0/2**(x*(1.0/12))
end
scaleLength = (@fbWidth - @nutThickness - 0.5*@fretWidth )
scaleLength = scaleLength * (1/(1 - _Nx12thRoot2Inv(@Nfrets)))
output scaleLength * (1 - _Nx12thRoot2Inv(@fretNumber)) + @xOffset + @nutThickness
Can anyone sort me out on this?
- strangeChild
- Posts: 47
- Joined: Sat Apr 27, 2013 8:04 pm
Re: Ruby nuby needs help
The file is stable now... and I didn't keep the version where this happened and can no longer replicate.
I believe it had something to do with the fact that I had saved some invalid code and then deleted it and saved again... after priming each input with a trigger the code saved properly.
I believe it had something to do with the fact that I had saved some invalid code and then deleted it and saved again... after priming each input with a trigger the code saved properly.
- strangeChild
- Posts: 47
- Joined: Sat Apr 27, 2013 8:04 pm
Re: Ruby nuby needs help
Hey - This is not strange - you may take a look to the definitions of Float and Integer
12 is interpreted as Integer
12.0 is interpreted as Float
For example:
1/12 means
Integer / Integer = Integer - An integer is an Integer so no dos will be stored
If you write:
1.0/12.0 means:
Float = Float/Float and you will get your expected Value
So ruby takes always the highes Level object in a line and converts it - This means:
1/12.0
Integers / Float = Float
1.0/12
Float / Integer = Float
If you want to convert values of a Variable:
Regards C.Hackl
12 is interpreted as Integer
12.0 is interpreted as Float
For example:
1/12 means
Integer / Integer = Integer - An integer is an Integer so no dos will be stored
If you write:
1.0/12.0 means:
Float = Float/Float and you will get your expected Value
So ruby takes always the highes Level object in a line and converts it - This means:
1/12.0
Integers / Float = Float
1.0/12
Float / Integer = Float
If you want to convert values of a Variable:
- Code: Select all
@var1=1
@var2=12
@var1 / @var2
=> 0
@var1.to_f / @var2
=> 0.08333333333333333
Regards C.Hackl
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
-
chackl - Posts: 233
- Joined: Tue Aug 17, 2010 8:46 pm
- Location: Austria / Salzburg
Re: Ruby nuby needs help
Yeah... once I figured out what part of my code didn't work I knew it was a typecast issue.
That's the downside of not having to declare variable types.
Has anyone else experienced problems saving files after a Ruby module with an error was deleted... that was my real problem here.
That's the downside of not having to declare variable types.
Has anyone else experienced problems saving files after a Ruby module with an error was deleted... that was my real problem here.
- strangeChild
- Posts: 47
- Joined: Sat Apr 27, 2013 8:04 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 72 guests