Object picking without collision

Hi all,
I know that there are a lot of questions regarding instance variables (I have also asked about them) and it seems like one has to have a condition to select an instance variable. For example if my player collides with an enemy I can get the (instance variable) health of that specific enemy.

But how about if I don’t have a condition (such as collision) for a specific instance and I want to give it an action?

Example: At the beginning of the scene I want to place instance #2 of the object “netLine” at a certain position while the other instances of netLine should remain as they where created.

How do I solve this?



Keep in mind there is no such thing as “instance #2” as far as the event logic is concerned. You would need to establish an ID variable for each object.

However, you’re not quite doing that in your events. You’re just saying “Change the variable linenumber of netLine: Add 1”. Since LineNumber will not yet exist for that instance, the initial value is 0. Meaning every netLine will just have a LineNumber variable of 1.

You would need to establish event logic setting up ID Variables of some kind, and track the current “available” ID for whenever you create a new object.

That worked. So if I have understood things correct, the instance variable has to be a string. I can’t just give each instance variable a value (number)?

This is my solution:



Oh no, I meant you could give the variable the name of ID, and just assign a number to the value. it can be whatever name you want.

Actually I understood that ID was just an example, but I didn’t see that I was replacing the same instance variable with a new value every time. Anyways, now I see what I was doing wrong. Thanks!

1 Like