Support

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

For general discussion related FlowStone

Ruby string randomizer

Postby kortezzzz » Wed Sep 21, 2016 3:34 pm

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] ?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby string randomizer

Postby KG_is_back » Wed Sep 21, 2016 3:46 pm

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

Postby kortezzzz » Wed Sep 21, 2016 5:30 pm

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 :?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby string randomizer

Postby billv » Wed Sep 21, 2016 7:20 pm

Hi Kortezzz..have you got brackets on the strings..eg: 'a','b','c'....?? It should work
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: Ruby string randomizer

Postby adamszabo » Wed Sep 21, 2016 8:41 pm

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

Postby kortezzzz » Wed Sep 21, 2016 9:00 pm

Hi billv and adamszabo,

Yes, that was the problem :D 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 :lol:
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
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby string randomizer

Postby KG_is_back » Wed Sep 21, 2016 9:39 pm

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

Postby kortezzzz » Thu Sep 22, 2016 12:11 am

Yes :D
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 8-)

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 :roll:

T***H***A***N***k YOU ALL :)
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby string randomizer

Postby RJHollins » Thu Sep 22, 2016 6:17 am

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

Postby kortezzzz » Thu Sep 22, 2016 9:15 am

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 :roll:
Any ideas?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 76 guests