Retrieving X POS of object name stored in alterable string - Easy?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hello! I usually find answers to all my questions in these forums, but this one has eluded me.

    I feel like this should be a super easy one.


    So, as we all know, retrieving the X Position of an object looks like: X( "OBJECT" ).

    In my case, I don't know the name of the object, but I DO have it stored in an alterable string called OBJECTNAME inside another OBJECT, so I put: X( OBJECTNAME ("OBJECT"))

    This returns a syntax error.

    What am I doing wrong? Is it not possible to do this?

  • For posterity, in case anyone else finds themselves in this situation; I got some helpful tips from some of the users in the Discord and here is the solution I found:

    First of all, you can't do what I was trying to do. Fusion doesn't allow it, the reason (I gathered) being that calling an object name that's in a variable would allow for a situation where that object doesn't exist and the program would crash or act unpredictably.

    The workaround is to start a For Each loop on all or a group of objects. On each loop you save that object's name and X&Y into some alterable values and start another loop that runs once.

    In the second loop you add a condition that the object name you saved = the object name you have stored, and save the X&Y you saved in the first loop into yet another alterable value. The reason for this is the for each loop is going to continue to run until it's checked every object, overwriting the XY of the one you wanted in the process, so you need to pull it out.

    Now you have the X&Y (or whatever else) you need! Here's what it looks like:
    Please login to see this attachment.

    So on the top line, I'm starting the for each loop.
    On the second line I'm saving all the values and starting another loop.
    On the 3rd line I'm saving the values elsewhere so they don't get overwritten.

  • X(Variable) wouldn't work because expressions and objects are paired together. One object can have an expression which another object won't. It would be impossible to tell whether the expression you typed is valid and the object you chose is capable of executing that expression.

    But if it were to happen, a lot of guards would have to implemented to fail silently on invalid input at runtime instead of at edittime, which is going to impact performance. (runtime = while the game is running, edittime = while developing the game in editor)

    You can simplify your solution by doing this:
    * Upon your action
    Group.Good : Set Alterable String A to OName$( "Group.Good" )

    * Upon your action
    * Alterable String A of Group.Good = "MyObjName"
    Counter : Set Counter to X( "Group.Good" )

    If I recall, in the next update you'll be able to choose "Compare to object's expression", writing OName$( "Group.Good" ) in the top box, and "MyObjName" in the other, omitting the first event above completely.

    That'll grab the X of the first object matching their name to "MyObjName". Ideally though you'd steer away from using strings this way as string comparisons get expensive.

    - BartekB

    Join the Click Converse Discord! - Please login to see this link.

  • Ah yes, that makes sense and looks better. I appreciate your simplified solution. I just got done redoing earlier sections of my project to make everything much cleaner like this.

    I've definitely tried to avoid using strings, as you suggest. This is a situation where I'm creating a series of objects and setting attributes/locations from a previous frame. I did that by packing all that information into a global string with delimiters. This problem arose as a result of unpacking that information into the following frame. Maybe there is a better way to go about moving game data between frames, and if so I'd love to hear about it.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!