I'm wondering if it would be possible to add the ability to directly modify proc arguments, sorta like pointers in C++, so that we can avoid having to create/copy a list and return said list every time to preserve variable changes in a proc chain.
Not sure on the details of how it would work, but if deemed feasible, I'm sure there are some people here who can offer some ideas.
Thanks.
ID:2110988
Jul 4 2016, 2:02 pm
|
|||||||
| |||||||
In response to Nadrew
|
|
True. Having to use a list seems very bulky in some cases though.
Here's the case I was considering when I posted this: // attempting to receive damage from attacker. In this case, I'm copying the args list because I need stam_dmg preserve changes through the event chain. Granted, I could leave out the information I don't need by doing damage_params = list(stam_dmg), but I'd much rather avoid having to use lists this way if possible. And so this topic came to mind. |
This feature request is for the ability to pass variables by reference. Normally, you can't actually pass a variable to a proc; when you write SomeProc(some_variable), some_variable is evaluated and the result -- the value contained in some_variable -- is passed to the proc. But what if you want to pass in a variable to be modified from inside the called proc?
C# does it with the "ref" or "out" keyword: class RefExample In DM, you currently have to "box" the value to a reference type, such as a list or a datum: mob A common usage for this in Unity is when you want to test for raycasts. If you cast a ray, the function returns true if the ray hits something, and the given "out" variable is assigned information about the hit. RaycastHit hit; // contains information about a hit, if any |
In response to Kaiochao
|
|
Exactly this post.
|
No copies needed, you can actually do this with the 'vars' list too, it's sneaky stuff.