1
2
ID:132958
Jul 17 2009, 2:12 pm
|
|
Another random question, but is it at all possible for DM to have a scope access operator? It could be very useful in scenarios where a datum exists to store certain information, but doesn't inherently need to be created by itself.
|
In response to AJX
|
|
bar |
In response to Popisfizzy
|
|
Popisfizzy wrote:
> bar Looks like you're talking about static objects? Anyway: This has been suggested before, and I think it is a good idea if it isn't too much work on the dev's end. If it is, then we can easily make do without it. If it isn't, it is a nice luxury. |
In response to AJX
|
|
Er, yea. Dunno what I was thinking.
|
In response to Popisfizzy
|
|
Popisfizzy wrote:
Er, yea. Dunno what I was thinking. ^.^ Happens to the best of us. Anyway.. I've encountered a few situations where I'd like the use of a static object but have obviously been unable to use one, so I instead used a single instance of the object that was created at startup and referred to from a global variable. Not the most ideal situation but definitely not the worst. I wouldn't really mind sticking to this sort of a setup if necessary TBH, though this is definitely something that could be considered if they reach a point where they are working their way down the To-Do list. |
Static variables indeed.
MyDatum =) |
In response to Nadrew
|
|
I was mostly looking for static procs. Apparently you can define them, but they fail to work.
|
In response to Popisfizzy
|
|
No surprise... you wanted it to work, but what's supposed to be the source object of that proc?
Of course, that was a rhetorical question, but since the answer is "nothing", then it shouldn't be an object proc. --- @In reply to Nadrew: [Snipped, whoops! static == global] And you could, of course, easily avoid the : operator there! I call heresy! |
In response to Kaioken
|
|
Me thinks you don't understand the use of static objects. There is a reason that I would want something as part of a datum but not globally defined. Hence the reason I am asking for it. It can work well enough in other languages, so why not DM? For that matter, are you not familiar with the functionality of the call()() proc? With it, you're able to call the procs of a given class without it being created. Is there some reason that is distinct from a static proc?
Also, why does a static variable work? By your logic, shouldn't they fail to work too? Perhaps you should know what you're talking about before you try to criticize, bucko. Generally helps you save face, 'cause you don't have to try and clean-up afterwards. |
In response to Nadrew
|
|
How come there's nothing on var/static/ in the DM Help window?
|
In response to Popisfizzy
|
|
Popisfizzy wrote:
Me thinks you don't understand the use of static objects. There are no static objects there. Also, I thought you were talking about static methods, not objects? As for calling the proc, obviously currently you could do that with a global instance, like everybody else. [...] For that matter, are you not familiar with the functionality of the call()() proc? With it, you're able to call the procs of a given class without it being created. Really? AFAIK, call() naturally requires not only an object but one specifically having the function, so would you demonstrate? The object proc syntax doesn't seem to allow no-object. Also, why does a static variable work? By your logic, shouldn't they fail to work too? There's no reason for it to fail. It's implemented as a run of the mill global var (that can't be changed). Naturally, that means you can access it from anywhere, even if you have no object at all. It's only an object var on the surface - it's not that all objects of those type keep a copy of it. So like a global var, it doesn't require an actual object to access. However, an object proc obviously does (unless, of course, they implement your suggestion to make this possible). Perhaps you should know what you're talking about before you try to criticize, bucko. Perhaps you should know what the other person is actually referring to before you criticize them (oh yeah, *angrily insert silly implicitly-slightly-degrading nickname here* ;)) Clearly, I was talking about what you've tried in DM, not a concept in other, unrelated languages. |
In response to Inuyashaisbest
|
|
There are kinda many undocumented features that aren't in the DM Reference. But this one here does exactly the same as <s>const</s> global, which is documented. static is just an optional other keyword for it for those familiar with other languages.
|
In response to Kaioken
|
|
Kaioken wrote:
There are no static objects there. Also, I thought you were talking about static methods, not objects? I am, but I was simply using it as a quick way to refer to the whole thing, and not just one part. As for calling the proc, obviously currently you could do that with a global instance, like everybody else. Given what I'm working on, that is the worst-possible way to do it (and pretty much impossible, to be honest), and the better alternative is to create a new type of each of the datum I'm using, which is terrible considering I will only be reading their variables and calling a function before they're deleted. Really? AFAIK, call() naturally requires not only an object but one specifically having the function, so would you demonstrate? Or you could look it up in the ref, but if that's so difficult: foo In the base code, I can't imagine that doing what Nadrew did, but with a proc, would be much different. Even if an object is created internally instead of just doing some sort of code lookup (Which isn't what happens, given that trying to access a variable of src causes a runtime error), doing the same with a static proc would, internally, almost certainly be extremely similiar I'd imagine, barring the addition of the static class for procs. The difference is that doing it with a static class, proc, or var instead of call()() allows for a much more dynamic way of doing it. So like a global var, it doesn't require an actual object to access. However, an object proc obviously does Which is why that part is already in the language. Perhaps you should know what the other person is actually referring to before you criticize them Funny how you say this yet are ignorant of what is already in the language. Clearly, I was talking about what you've tried in DM, not a concept in other, unrelated languages. Clearly if it's been implemented in multiple, widely-used languages it's not a crazy thing to do. And given that it doesn't cause a compiler error, there must be something about it that was worked on to some extent, or at least planned. |
In response to Kaioken
|
|
Kaioken wrote:
You could also use const, but that's just another name for static. That statement is false. A const is a constant value, that cannot be changed. Ever. A static is a static value, that can be accessed without an object of that type existing. A static variable is a variable that is the same for all objects of that type, even though you don't even NEED an object of that type to access it. This CAN be changed. obj/var/static/Test=1 If you unquote that last line it will produce errors because you're trying to change a const. The rest operates appropriately. |
In response to Popisfizzy
|
|
Popisfizzy wrote:
Given what I'm working on, that is the worst-possible way to do it (and pretty much impossible, to be honest), [...] Okay, if you say so. Or you could look it up in the ref, but if that's so difficult: Yeah yeah, random accusations. =P "You could close your <DM> tag, but that's so difficult". I looked it up, but the Reference entry seems to imply the first syntax call(ProcPath) is for global procs only, so I assumed so. My bad. I don't know how that works though, so it might be internally creating an object or not. Procs can run with no src once they're already started. At any case, considering call() is not the normal way to call procs, it was irrelevant until you've brought it up. But no matter. Clearly if it's been implemented in multiple, widely-used languages it's not a crazy thing to do. Sure, I haven't claimed so. Neither did I claim I knew everything about multiple, widely used languages. And given that it doesn't cause a compiler error, there must be something about it that was worked on to some extent, or at least planned. Actually, that part is meaningless. Dream Maker is very lenient in certain specific aspects of the language, such as this one. You can get away with a lot without causing a compiler error, so it doesn't mean anything about what's in the language or was planned. Even this compiles, although it makes no sense: var/const/global/tmp/static/A For that matter, even this: var/const/global/tmp/static/non/existent/type/A ... compiles, until you try to actually use the variable A. |
In response to Kaioken
|
|
Uh, wrong.
|
In response to AJX
|
|
Whoops - got me there. I got confused - I meant that in DM, static is the same as global, not const. I never use that name of modifier, so I forgot. >_>
EDIT: Also, FYI this means if you don't need to access it dynamically, you don't actually need to look for it at runtime through the type. You can tell Dream Maker to grab that var at compile-time by defining the var as the object type (but no need to actually set it to a reference) and accessing the var. SomeObject |
In response to Kaioken
|
|
Actually, it's like a global variable that can only be accessed via an object it belongs to (I can't really describe it too well, it's a weird concept).
var/information/I = new |
In response to Jeff8500
|
|
Apparently, you've missed my point. You've replied to my post which said the static modifier is the same as the global modifier, meaning these 2 lines are equivalent:
mob Then, you've said what those modifiers do, which is unrelated to my post. As for the explanation, this isn't very different from a normal (under no object) global var - mainly, only the syntax used to access the var differs. It's a "fake" object var, intended to keep the project tidy by allowing assorted global vars to only be accessed when the object "responsible" for them is involved, but as demonstrated throughout this topic, it's possible to access them with no object at all, through 2 methods - one involving a var defined with the object's type (but not initialized to it), or a var which has the object's type path as its value. |
1
2
I googled this and it didn't come up with any answers... Just scope resolution operators and other things. Could you give a slight explanation of what this is, for us less edumakated peoples? Ty :)