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 string randomizer
12 posts
• Page 1 of 2 • 1, 2
Ruby string randomizer
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
How can we change this code to deal with string values like [a,b,c,d] ?
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] ?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby string randomizer
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.
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Ruby string randomizer
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
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby string randomizer
Hi Kortezzz..have you got brackets on the strings..eg: 'a','b','c'....?? It should work
BV MUSIC SYDNEY AUSTRALIA..Songwriting and Software development
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
- billv
- Posts: 1157
- Joined: Tue Aug 31, 2010 3:34 pm
- Location: Australia
Re: Ruby string randomizer
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
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Ruby string randomizer
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.
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.
- Attachments
-
- (string replace problem).fsm
- (584 Bytes) Downloaded 839 times
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby string randomizer
in the line " find=/\b#{@find}\b/ " change it to " find=/#{@find}/ ". Basically remove the "\b" parts.
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Ruby string randomizer
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
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
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby string randomizer
can you post an example with the 'Edit Box' you're using?
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: Ruby string randomizer
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
12 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 56 guests