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 constants
24 posts
• Page 2 of 3 • 1, 2, 3
Re: Ruby constants
I know what self is, this wasn't the question. The question is, why you define a method explicitly with self (which makes it static).
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby constants
MyCo wrote:Is it safe to assume, that all RubyEdits are initialized, before they receive external Inputs from other components
I'd want to test some more, but it certainly seems that way - what appears to happen is..
- 'init' run for all RubyEdits
- triggers from any 'output' methods in init get buffered.
- Green starts, and acts on the buffered triggers
- 'event' methods of Rubies act on the triggered data as usual.
I've not yet been able to trip this up by copy/pasting to change the startup order - but, as with you, I have only tried it so far on small schematics with only a few Ruby editors.
MyCo wrote:For the constants problem? From the documentation it looks like this should lock the variable. But in FS, when I try it, I still can change the value. Don't know what's going on there
Yes it's not what I expected either - but it is consistent with Ruby.
Variables are just pointers to objects - so the freeze command doesn't lock the variable, it locks the object to which the variable is pointing. So you can then no longer modify the object by calling its methods - but you can make the variable point to a different object entirely., because the '=' is an assignment, not a method call with the object as its receiver.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Ruby constants
I've played around, and it doesn't work in bigger schematics. Looks like the trigger in this case is sent out before other elements are initialized. When the elements get initialized later, they don't even get the last value from the input, instead they used the values that were stored when the schematic was saved.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby constants
MyCo wrote:I've played around, and it doesn't work in bigger schematics
Dammit - I thought it was a bit too good to be true.
The only workaround I can see is to use an external trigger (After Load prim' ?) to trigger the value send - or maybe schedule a Ruby event from init to trigger it. But then, of course, you've got to make sure that nothing else reads it before that happens (or at least tests for that case and can handle the exception).
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Ruby constants
I've already tried the "After Load" that you mentioned. This actually works, but in other RubyEdits you have to make sure, that the callback object is valid. Because there could be other triggered events before the Ruby Callbacks initial "After Load" comes in. Therefor I use "begin... rescue...end".
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby constants
MyCo wrote:Callbacks initial "After Load" comes in. Therefor I use "begin... rescue...end".
Yes, I'm starting to feel the need to look into that too - had a few times where resolving execution order was a lot harder than I though it would be.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Ruby constants
MyCo wrote:I know what self is, this wasn't the question. The question is, why you define a method explicitly with self (which makes it static).
def self.Const
1
end
If you send any message to self (e.g., self.Const) it is calling the Const method of your class.
Const= is just a setter method. If you want Const to be a variable, you must not use self.
-
digitalwhitebyte - Posts: 106
- Joined: Sat Jul 31, 2010 10:20 am
Re: Ruby constants
As far as I understand it, if you define a method with self, you get a static class method. And actually, you don't need static methods in FS Ruby, unless you want to create multiple instances of a class... which you can't do with RubyEdit.
Here is what I mean:
Here is what I mean:
- Code: Select all
class Test
def self.Const
1
end
def Const
2
end
end
watch "static", Test.Const # outputs 1
watch "instance", Test.new.Const # outputs 2
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby constants
Another Ruby question:
Why does the ruby interpreter completely locks up, when you just type:
is there an outer loop, that we can't see?
Why does the ruby interpreter completely locks up, when you just type:
- Code: Select all
redo
is there an outer loop, that we can't see?
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby constants
Ruby redo Statement:
Syntax: redo
Restarts this iteration of the most internal loop, without checking loop condition.
Restarts yield or call if called within a block.
Syntax: redo
Restarts this iteration of the most internal loop, without checking loop condition.
Restarts yield or call if called within a block.
-
digitalwhitebyte - Posts: 106
- Joined: Sat Jul 31, 2010 10:20 am
24 posts
• Page 2 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 75 guests