Ruby Syntax not quite right

For general discussion related FlowStone
Post Reply
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Ruby Syntax not quite right

Post by JB_AU »

I'm trying, i think , i know i haven't got the syntax/formatting correct.
Is there a package of Ruby examples that show basic programming, i.e. if..then , case, for, while & do etc?
almost.fsm
(438 Bytes) Downloaded 982 times
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: Ruby Syntax not quite right

Post by TheOm »

For learning ruby I would recommend this:
http://www.codecademy.com/tracks/ruby
And of course the Flowstone UserGuide for the FS-specific stuff.

I hope I understood correctly what you wanted to achieve. I took a different approach without a case statement.
Please ask, if you need explanations on specific things in the code.
Attachments
fix.fsm
(25.8 KiB) Downloaded 988 times
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Ruby Syntax not quite right

Post by JB_AU »

I am reading "Programming Ruby 1.9.2" Chris Pine, my problem is i want to find 'case' statements , but this book does not cover them :( actually not many books do o.O
So some examples of the syntax is more important as it will show how to format ruby in flowstone.
I am unsure if variables need to be defined/declared as my understanding so far is, that they are object until they hold a value.

I see what you have done , it is what i need the component to do & thankyou, but it evades how to do it with a 'case' statement & where the syntax is wrong.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Ruby Syntax not quite right

Post by RJHollins »

Here's a small basic example I started with ...
Case Statement [RJH]-1.fsm
(429 Bytes) Downloaded 998 times


Hope this helps a bit 8-)
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Ruby Syntax not quite right

Post by JB_AU »

Rj that confirms my understanding of 'case' statements in ruby/fs to be correct i am only now missing how i have laid it out to be correct.
I see from Om's example i need to declare the variable.
Om's example is really good , much shorter than using a 'case' & more fluid.

Yet i do not understand how the variable @counter can take the input from @Count when there is no reference in the code for @Count, where does the magic connection exist ?
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: Ruby Syntax not quite right

Post by TheOm »

JB_AU wrote:I see from Om's example i need to declare the variable.

It just has to be declared outside of the event function, otherwise it would be reset everytime there's a trigger.
JB_AU wrote:Yet i do not understand how the variable @counter can take the input from @Count when there is no reference in the code for @Count, where does the magic connection exist ?

I am not referencing @Count because there is no value to read out from a Trigger connector.
I used to think that the triggers are just booleans that turn on and off very quick too, but they aren't.
But what you can do is get the index of the triggered input, via the first argument of the event function(i in this case).
So in this line:

Code: Select all

@counter += 1 if i==1

I'm incrementing @counter when the second input to the ruby component was triggered(@Count).
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Ruby Syntax not quite right

Post by JB_AU »

Ohhhh!

That explains a lot , i too was living the fantasy that High=True / Low=False , you have rudely woken me up :)

Ohhh! I have to go salvage my pride.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
Post Reply