rlr wrote:but where is input 100?
There is no actual input 100 - but it is exploiting the way that Ruby works when it "talks" to the connectors...
When the green values come in, they have to be turned into a format that Ruby understands - so each value is "translated", the value put into the '@ins' array, and tagged with the input number, so that the 'event' part knows where the value came from.
Ruby doesn't really know or care whether there's a real input there or not - as long as it sees those 'tagged' values, it will fire the 'event' section anyway. So the 'input 100' is just creating an event, totally inside Ruby, that 'looks like' a real input. You can send one of these 'internal messages' to an input that does have a real connection too, if there was ever a need to.
With a bit of Ruby trickery, you can even send input messages to a completely different Ruby primitive, or even one in a different schematic - though those are 'party tricks' rather than good programming practice!
I guess they chose 100, because no-one is ever going to want 101 inputs, so it leaves plenty of room for 'real' inputs if you decided to add more. You might think that would make the @ins array get a bit big - but, as I understand it, in Ruby arrays are implemented more like hashes - there really is nothing there for empty array entries, rather than using up memory storing a 'default' value like the 'green' ones.
(You wait, someone will go for a 101 input Ruby now that it's been mentioned!
)
Jay wrote:Ive made some completely useless items
Phew, thanks for sparing us, and only posting the nice examples of some important Ruby fundamentals!
And the rand thing is cool, i didn't know it understood ranges like that - very useful.
No big howlers as far as I can see. One tip - triggers don't send or receive a value, so storing a value in the trigger example isn't needed. You can emulate a green 'pure trigger' in Ruby with the special value 'nil' - 'nil' represents literally nothing, and in Ruby is a very distinct concept from 'false' or 'zero'. But I think pretty much any value is fine, as it will be safely ignored anyway if the output is set to be triggers.
Jay wrote:In the random float int modules how do i get them to start with zero values?
You can make a startup routine by writing a method called "init". That method name is recognised by FS, and will always be run first when the module starts up (or you edit any code). So you can set start values of variables there, and all the FS "purple" Ruby commands work too, so you can zero your outputs.
- Code: Select all
def init # NB) init should not take any arguments
output 0,0
end
And if you ever need to do a manual 'reset', just put 'init' in your code, and you can call it yourself.
The only thing to watch is that at load-time, Ruby starts before 'green' does, so input values will always be whatever got saved to HDD inside your schematic, because there are no 'green' values yet for 'init' to read - not a big problem, but something to watch if you are relying on green prim's to get values for things like sample-rate, as 'init' will miss any changes.
Easy init !?.
(Oh, I hang my head in shame, i really can't believe my humour has stooped so low
)