5 code lines polynomial waweshapr (green)

Post any examples or modules that you want to share here
Post Reply
unkargherth
Posts: 29
Joined: Fri Apr 08, 2005 9:46 pm

5 code lines polynomial waweshapr (green)

Post by unkargherth »

The simplest form of a polynomial waveshaper for green floats. Version 0.1 Alpha

TODO:
.- Convert to Mono
.- Allow more math primitives

simplepolywaveshape.fsm
(7.04 KiB) Downloaded 1471 times
Free your memory, .. with a free(). Like a pointer
Cast a pointer into an integer and it becomes the integer...
Cast a pointer into a struct and it becomes the struct...
A pointer can overflow... or can crash...
Be a pointer my friend
User avatar
nix
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: 5 code lines polynomial waweshapr (green)

Post by nix »

ruby error.png
ruby error.png (20.45 KiB) Viewed 17319 times

I'm getting this error.
I don't know what I'm doing,
I haven't learned waveshaping
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: 5 code lines polynomial waweshapr (green)

Post by trogluddite »

Looks like t's telling you that you haven't give the variable @x a value yet. Undeclared variables always return nil.
What is probably happening is that when you retype code, the whole primitive is parsed again, and this sometimes clears the values in the input variables. Ruby primitives don't "request" values from upstream modules like green does, you have to push a value in from outside, so after an edit you sometimes need to refresh the input values by triggering them. This also means that input values don't default to zero like they do in green - if you haven't triggered an input yet, it will always show nil - this is catching me out all the time too.
Best thing to do is to put a test in the code, e.g.

Code: Select all

if @x
  #do some stuff with @x#
else
  raise "@x is not set yet in MyMethod"
end

The raise command send an error message to the console - using this inside your method definitions will make bug tracing 100% easier.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
unkargherth
Posts: 29
Joined: Fri Apr 08, 2005 9:46 pm

Re: 5 code lines polynomial waweshapr (green)

Post by unkargherth »

OK. my mistake. Seems to be solved if the line reading

Code: Select all

output eval(@toEval)

is changed to

Code: Select all

output eval(@toEval) if (@toEval && @x)
Free your memory, .. with a free(). Like a pointer
Cast a pointer into an integer and it becomes the integer...
Cast a pointer into a struct and it becomes the struct...
A pointer can overflow... or can crash...
Be a pointer my friend
Post Reply