How do I represent a object using a global variable?

0 favourites
  • 10 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • So, I want to make a beam from an object I selected to another object I select later.

    I represent that object I selected with a global variable.

    Now obviously when I do this, I get an error "'CurrentSelected' is not an object. "

    Because it's obviously not an object:

    But this is frustrating because in other game engines I can do this just fine as long as I wait for the game to create that instance of that object with something like " waitforchild("Childname") " The child's name being stored using a global variable.

    I can't do this in Construct 3 the traditional way, so how would I do it the funky construct 3 way?

  • You can pick it by UID where the UID is stored as a global variable. If you want to give it a name you can use an instance variable str on the object.

  • lionz So for reference I have a Global variable " CurrentSelected " I set that to the UID Of the last object I clicked before clicking the second object and making a beam between the two?

    I'll try it, sounds like it might actually just work.

  • Yeah if you use a Family which contains all objects or you won't know which object type to pick.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Can't seem to get that to work,

    I might just have "CurrentSelected" do what it already does and simply use it to store data on what I have selected.

    Have a group store every possible connection referenced by two instances of CurrentSelected,

    Then have two instance variables on the link beam ( link 1 and link 2 )

    Along with a third called "Data" to return the type of connection made based on the name.

  • Here's one way to do it:

    dropbox.com/s/2j144iheff6rrde/lines_between_sprites.capx

    The only finicky bit is having to use pick all before being able to pick a different instance.

    Here's a variation that uses two instance variables which is a bit cleaner imo.

    dropbox.com/s/5w5xwxi1nnvgm8g/lines_between_sprites2.capx

  • Pardon the late response: This method *works* but there are acouple problems I've had with it.

    Firstly, I obviously can't move the object I make a connection to otherwise the link will break ( I mean by using a drag and drop behavior ).

    Secondly, when it comes time to connect different objects together; They actually won't connect unless I make a variable for every possible connection.

    ( Which I won't do because I value time quite abit. )

    This gif shows both problems in motion:https://i.gyazo.com/9113f1d48c56c5b87e151cf839f6ce31.gif

  • I'm legitimately considering using the Javascripting service to get around this problem because at the current moment I don't have the brain power to understand how Id use the code-blocks C3 offers to make what I'm trying to make.

    I suppose I should explain what it is I'm making:

    I am making a simplified, dumbed down coding interface for a game I wanna make.

    But I need some way to get every expression/variable the player uses to interact with each other and send data so that the player can make their own "script".

    The way I was planning on going about this was, I have a variable ( those "and", "Function", "OBJ", "Then", etc etc sprites you see on screen ) Then by clicking on one variable and another, you make a link.

    This link sends information which is then processed by the system to get a read on what the player is writing for example:

    IF > OBJ( Door ) > MEM( Closed ) Then > MEM( Open )

    Super simple; Causes a door to open if its closed, and it gives my game something unique I can build puzzles around.

    I think Id be done by now if I could reference objects using variables but C3 simply won't allow it and trust me I've looked up and down and read paragraphs worth of stuff on their system expressions & variables help page for an alternative way of doing it.

  • Here's an updated way to do the connections. Basically a separate edge sprite that stores the two connected object uids. The example works with one sprite type but you can use a family of sprites instead.

    dropbox.com/s/lsazeyasqrsa2g6/lines_between_sprites3.capx

    The scripting idea is interesting but you probably want to nail down how you want it to work precisely before implementing it.

    Simplest to me would be similar to how construct's events work. Maybe something like:

    if object:condition then object:action
    if door:opened then door:close

    Or maybe this? This may be better suited for visual scripting. The flow would be top down/left right. You'd have three building blocks.

    * "object:condition" which only continues if true
    * "else" which runs if the connected condition is false.
    * "object:action" which does something.
    door:closed -> player:hasKey -> door:open
    event:clicked
    |
    v
    door:unlocked-> else -> playSound:doorRattle
    |
    v
    door:opened -> door:close -> playSound:slam
    |
    v
    else -> door:open -> playSound:creak

    Anyways, just some thoughts. I suppose the conditions could be made more distinguishable somehow. The ideas can be extended but I think simple is key. To run it you can either have it trace down the list and do stuff a step at a time or build some other intermediate form. Again, I think simpler is better because it reduces the need to check for invalid linkages. As is you should only need to check to make sure you didn't create any loops with the links.

  • This works! With some modifications.

    ( I had already thought of this part )

    I made a library/table for the possible connections and exceptions, integrating that with this connection system ( with modifications being that I have it move to invisible sprites named "Receiver" and "Sender"; Sender being where it starts and Receiver being where it ends. ) These invisible sprites always position themselves with a function kinda like an image point.

    This way I don't have to copy and paste this whole thing over and over for each function.

    For communication I have a group referencing everything in the library/table using event triggers, then a variable in each function to confirm the connection was correct.

    It runs a script in the background that gives the function its functionality, I plan on doing this to objects in my game, there will be the fake coding system you can see with the rest being handled by a script in the background ;)

    I had always thought of how Id approach it, but upon tinkering with the connection part; It seemed to have been abit more of a challenge than initially thought.

    Weird too because I thought giving each function functionality would be the hard part.

    Definitely crediting you for this! You have no idea how frustrating it was for me when I have everything else done but this small little detail!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)