Open Jase0000 opened 8 months ago
Workaround: issue69_workaround.zip
Another (not very pretty) workaround might be to pick the last created object's UID to a local variable first, then creating a new one by name, then picking the last created again and comparing if its UID matches the one in the variable (which means the creation failed). Haven't tested this though.
For fun, here is a function that returns 1 if there is an object with the name, and 0 if there isn't. You can put this return function into an "evaluate expression" condition by itself, since non-zero expressions make the condition pass.
{"is-c3-clipboard-data":true,"type":"events","items":[{"functionName":"objectNameExists","functionDescription":"","functionCategory":"","functionReturnType":"number","functionCopyPicked":false,"functionIsAsync":false,"functionParameters":[{"name":"name","type":"string","initialValue":"","comment":""}],"eventType":"function-block","conditions":[],"actions":[{"type":"script","script":"runtime.setReturnValue(runtime.objects[localVars[\"name\"]] ? 1 : 0)"}]}]}
Reviewed guidelines
Checked for duplicate suggestions
Summary
When using "Create Object By Name", if you enter an invalid name, nothing happens - Then you would have "Pick last created X", which will end up picking an entirely different object since the "Create Object By Name" action failed!
To be able to throw a condition in for "Does Object Name Exist?" and enter the object name, then could prevent this kind of issue from occurring.
Possible workarounds or alternatives
The workaround would be to "never" allow this to occur in the first place. Generally safe when inputting an object name directly into the action, a bit more risky when using variables to create objects.
Proposed solution
A new system condition "Does Object Name Exist?"
Why is this idea important?
If it's generally straightforward to implement, this would be a nice way to keep things clean and prevent unusual issues from occurring if events were incorrect, especially for beginners or even seasoned individuals who are making a complex system utilising "Create Object By Name".
I can only foresee one "important" issue, which could be someone finding a glitch/exploit in the game that allows them to modify a variable to something it shouldn't be, perhaps even a hacker in an online multiplayer game that changes a Dictionary variable that holds the object name to be created, could cause unpredictable issues.
Additional remarks
No response