Picking newly created object

0 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi

    I have a function that can generate objects when passed a parameter for instance "Stone" and it will then create a stone at the player position, and set a global variable "Last_generated_item" to its UID.

    However If I in the next sub event do "pick item with UID = last_generated_item" it doesn't select it. I am aware of the newly picking thing problem. However if I use "wait 0" it still doesn't work.

    I have also tried adding a "system object with UID exist" in the next sub event and print out the UID of the "last_generated_item" to a text object and it works fine. So I guess the object must be there to be selected as I can get the UID of it.

    However if I move the text object to the event with the "pick item with UID last_generate_item" it doesn't react to it.

    Now the weird part is I do the exact same thing else where in my game, and it have no problem selecting the "last_generated_item" even without a "wait 0". So why it doesn't work here is really weird.

    I have also tried to return the UID of the object created in the function and use the "returnvalue" instead and it give same results as using the global variable.

    The only difference that I can see, is that the first ones were made in another version of C2 and this is made in latest beta version. However cant see why that should make a different.

    But anyone have any idea why it doesn't work? And if im doing it wrong, how would you correctly select an object that was made in a function?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • can you include a capx?

  • I dont think it would make much sense to link the whole capx as its pretty complicated, and would take a long time to go through.

    But here are some screenshots of the ones that works and the ones that doesn't.

    This one fine.

    Pic 1 - Working

    This one doesn't.

    Pic 2 - Not working

    To explain what it is suppose to do, to make it a bit easier to understand. When the player right click an item that can be equipped, and the slot where its going to be equipped is empty, it will spawn an item and move it to the correct equipment slot, in this case "hands".

    What the generate item function does, is simply to create an item, based on the input, and drop it at player.x player.y position, then the idea is to store the item that was generated in the "Last_generated_item" variable. And then select it afterwards and do whatever it have to do. In this case it should move it to the equipment slot.

    However it wont do that, and just drop the item at the player position.

    In the first picture, its the same, except the item is moved to the player inventory, and that works fine. The trigger for that, is a left mouse click on a sprite button.

    I tried to add a global variable and store some kind of action here like "Equip_item_in_hands" and then in the on create function of the item, check if that variable is that, and then move it. But that doesn't work.

    So how you would create an object when you mouse right click, and then make it do something I cant figure out. So frustrating how picking objects works I think, I don't trust it <img src="smileys/smiley19.gif" border="0" align="middle">

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