Last Switch(Ruby)

For general discussion related FlowStone
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Last Switch(Ruby)

Post by billv »

Had lots of silly attempts at this over last few weeks...
have stripped it down to this....

Code: Select all

def event i,v
  if i==0 then
  output 0,@firstsignal
  end
  if i==1 then
  output 0,@secondsignal
  end
end

I want it to behave just like the standard "green" Last Switch.
Seems to work right...but it's a real important part...and I've stuffed it up a few times now...
so I want to make sure...before i stick a few hundred in my schematic..
Can anyone see a problem with this code....??
Is there a better way...?
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Last Switch(Ruby)

Post by MyCo »

Code: Select all

def event(i,v)
  output(v)
end
User avatar
nix
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: Last Switch(Ruby)

Post by nix »

I think the inputs will sum MyCo?
Bill, I have done exactly the same thing,
I think it works fine.
Cheers
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Last Switch(Ruby)

Post by billv »

Great.....thanks guys.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Last Switch(Ruby)

Post by MyCo »

nix wrote:I think the inputs will sum MyCo?


No, why should they?
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Last Switch(Ruby)

Post by billv »

Works great Myco....
I thought the inputs would needed to be declared individually....
I had no idea i could get away with that.. :D
Cheers
User avatar
nix
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: Last Switch(Ruby)

Post by nix »

oh ok sorry-
I don't know what i was thinking there
That's neat as MyCO, will use it too
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Last Switch(Ruby)

Post by RJHollins »

Ahhh ... for the 'slow' learner crowd ... apparently me :o

I tried a very simple input [ 0 or 1], along with inputs for the the 2 variables ... I could not get this to work consistently :shock:

This seems that this should be a simple choice and path through the code ... If 'this' ... this, if 'that' .... that.

How I'm screwing this up is ridiculous .... I'm embarrassed, but can someone shed light on this please :oops:

Thanks.
:roll:
User avatar
nix
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: Last Switch(Ruby)

Post by nix »

last.fsm
(524 Bytes) Downloaded 1086 times


Here are 3 variations, 2 of Bill's and the MyCo one.
I think the problem u had was not naming the inputs.
np with asking- it's how I finally cottoned onto this program a little
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Last Switch(Ruby)

Post by RJHollins »

Thanks Nix !!

It was the 'Trigger' :shock:

I had mine similar to your 2nd example ... BUT ... I also had a 3rd INPUT variable (i). :roll:

Obviously, still struggling to get a handle on the basics of RUBY. I'm hitting those posted RUBY sites to get familiar. My only programming 'experience' was using GFABasic on the ATARI ST back in the 80's. :lol:

When I looked at this "Last Switch', I saw an input [i], and 2 result variables. So on the left side of the RUBY box, I had 3 string inputs [labeled] ... i, firstsignal, secondsignal. I thought changing i from 0 to 1 would toggle the output through the IFTHENELSE routine.

Still don;t understand why this didn't work ... also [now] not sure what the 'DEF event i,v' is really doing. I thought this was telling RUBY to watch for 'i' and output to 'v'.

ahhh ... soooo much more to learn.
Post Reply