Page 1 of 2

Last Switch(Ruby)

Posted: Mon Aug 05, 2013 7:47 am
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...?

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 8:03 am
by MyCo

Code: Select all

def event(i,v)
  output(v)
end

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 8:21 am
by nix
I think the inputs will sum MyCo?
Bill, I have done exactly the same thing,
I think it works fine.
Cheers

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 8:35 am
by billv
Great.....thanks guys.

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 5:16 pm
by MyCo
nix wrote:I think the inputs will sum MyCo?


No, why should they?

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 8:43 pm
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

Re: Last Switch(Ruby)

Posted: Mon Aug 05, 2013 10:37 pm
by nix
oh ok sorry-
I don't know what i was thinking there
That's neat as MyCO, will use it too

Re: Last Switch(Ruby)

Posted: Tue Aug 06, 2013 8:50 am
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:

Re: Last Switch(Ruby)

Posted: Tue Aug 06, 2013 12:16 pm
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

Re: Last Switch(Ruby)

Posted: Tue Aug 06, 2013 6:40 pm
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.