Page 1 of 2
Ruby string randomizer
Posted: Wed Sep 21, 2016 3:34 pm
by kortezzzz
Hi,
Just another ruby challenge:
There is a quite nice ruby randomizer code posted on the forum some while a go which is great for floats. The current code outputs 0-4 values in random order
Code: Select all
def init
end
def event i,v
@array=[0,1,2,3,4]
if i == 0 then
output 0,@array
end
if i == 1 then
@randarray = @array.shuffle
output 0,@randarray
end
end
How can we change this code to deal with string values like [a,b,c,d] ?
Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 3:46 pm
by KG_is_back
It should work with any type of array. You should be able to simply change the connector from float array to string array and it should work.
Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 5:30 pm
by kortezzzz
Well, It doesn't. It only works if you deal with numbers, but not if you change it to anything else like letters or symbols

Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 7:20 pm
by billv
Hi Kortezzz..have you got brackets on the strings..eg: 'a','b','c'....?? It should work
Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 8:41 pm
by adamszabo
try this
Code: Select all
def event i,v
@array=['a','b','c','d','e']
if i == 0 then
output 0,@array
end
if i == 1 then
@randarray = @array.shuffle
output 0,@randarray
end
end
Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 9:00 pm
by kortezzzz
Hi billv and adamszabo,
Yes, that was the problem

everything is just fine now.
Thank you!
Since I'm kinda sick a little and gave up for working today, I'm trying to take advantage of this free extra time and put some stuff together in some of my old projects. That's why I bother you guy with ruby questions for the whole day
And still have some loose ends here and there. Here is another one:
Trog posted a long while a go a "ruby-replace string" code. Very useful one, but yet suffers from some lags.
example:
I would like to replace a "space" (which actually means an empty string primitive) with the string "$".
The problem is that code would replace the "space" with "$" correctly, but as long as the sentence contains only letters and numbers. If any symbols added in the sentence (like "%", "*", "@", etc.), it just passes over the replace rule and leave it as a"space". Maybe I just do something wrong?
Attached a little schematic for testing.
Re: Ruby string randomizer
Posted: Wed Sep 21, 2016 9:39 pm
by KG_is_back
in the line " find=/\b#{@find}\b/ " change it to " find=/#{@find}/ ". Basically remove the "\b" parts.
Re: Ruby string randomizer
Posted: Thu Sep 22, 2016 12:11 am
by kortezzzz
Yes
Thanks KG!
Guys, you made my day. Thought it's just another wasted one, but I almost finished my whole fix list thanks to you
There is only one fix left for today, but I'm not sure it would be that easy...
Do you know that old lag with the edit box? I mean when you type something in it and the whole stuff just disappear randomly in the middle of typing? Wondering if there is any creative way to fix this
T***H***A***N***k YOU ALL

Re: Ruby string randomizer
Posted: Thu Sep 22, 2016 6:17 am
by RJHollins
can you post an example with the 'Edit Box' you're using?
Re: Ruby string randomizer
Posted: Thu Sep 22, 2016 9:15 am
by kortezzzz
can you post an example with the 'Edit Box' you're using?
Nothing special. Just the stock one. Yesterday I started to play with it a little, and found something interesting:
When you add the edit box in one of your schematic's internal stages, it won't behave wrong as long as you try to edit the text from that stage. But once you try to edit the text from the "top" stage, the problem occurs
Any ideas?