Whenever you refer to a variable who does it belong to by default? The src, usr or neither? Is it possible to create a verb that edits the default value of a variable for everyone permanently? A way to turn a tmp variable into a regular variable through a verb(Not that I need to do this, was just curious)?
Something a little off topic, can you create a verb that creates verbs(completely create one from scratch, not create one from a precoded placeholder)?
ID:1609948
Jun 25 2014, 9:03 am (Edited on Jun 25 2014, 9:15 am)
(See the best response by Stephen001.)
|
|
I'm gonna break this down, because this is like ... 6 posts in one right here.
Gluscap wrote: Whenever you refer to a variable who does it belong to by default? The src, usr or neither? As Insomniaddikt has explained quite well, it depends on scope and context. var/varA = 0 Is it possible to create a verb that edits the default value of a variable for everyone permanently? The short answer is yes. The long answer is yes, but you need to consider what you mean by 'everyone' and what you mean by 'permanently' in order to actually create such a verb. If 'everyone' is mobs associated with clients in the world, loop on clients. If permanently means it's persisted to savefile, remember to save each client mob to savefile accordingly. If everyone includes offline people, you need to go trawling and loading mobs from savefiles, then writing them back. All doable quite comfortably in DM. A way to turn a tmp variable into a regular variable through a verb(Not that I need to do this, was just curious)? Well, the distinction is whether it's saved or not. You can put said tmp variable's value into a savefile yourself via a verb, and change your savefile loading code to test for and sets the value if it's present, yep. It probably just shouldn't be a tmp variable in the first place though. Something a little off topic, can you create a verb that creates verbs(completely create one from scratch, not create one from a precoded placeholder)? Provided you are happy to have a world reboot, trusted mode, access to the full source code, and suitable access to dm.exe or DreamMaker, yup, sure. Is it smart to do? Nooooooooooooooooooo. |
In response to Stephen001
|
|
Your code example for scope is what I had in my head, and just for some reason could not write out. :P Thanks for helping clarify on my explanation.
|
Variables are owned dependent on the scope they are defined in. For example, if you have a class with their own variables, then they are owned by whatever that class instance is:
As well, a function can have a local scoped variable, that is untouchable from a global source:
There are also application-specific global variables that DM introduces, which you can just declare:
If you want more understanding of how variables and their scopes function, see: https://en.wikipedia.org/wiki/Scope_(computer_science).
I can't think of any examples or languages that allow an example of changing default values at run-time, but there are certainly hacks around this. One is really ugly, but you may be able to get away with using static variables to be able to modify at runtime for all new classes. Something like this might work:
^ This isn't entirely permanent, as it can always be manually changed later, but you certainly have control over how it gets changed. If you want it to only be changed once and never again, this will certainly work.
This isn't really something that can be done (unless I'm completely missing the point of what you are looking for), but I'm sure you can hack it in some way. A potential example may be something like:
However, while I suppose the above is possible, I don't see why you'd ever need it.
Really, no. Because you can't compile at run-time, you'd have an immensely difficult time creating the flexibility of an actual verb and then compiling. I mean, if you wanted to spend several hours creating a mini-compiler within your own game, I suppose it would be possible, but you'd be better off configuring a system within the game for custom actions and tailoring it to what your needs would be.
Edit: Though not very related, if you were creative enough, you might be able to get something useful from Kaiochao's response to my question on this thread. This may at least help in a bit of developing more dynamic functions, where argument sizes and functions aren't necessarily known.