Any way to set focus or create a variable object? [SOLVED]

I’m trying to give and order to target an object that should vary constantly.

To be more precise, a turn based system where, after selecting the ability, you can select 1 out of 4 enemies to attack (and deal damage).

Is there any way to set focus on an object, and then be able to select that focused object object (as a variable) to attack it (deal damage, move toward, etc.)? Cause, as far as I can tell, you can only deal damage and move toward objects and groups; I don’t see any other option.

Also, I want to do it that way because there will be at least 4 playable characters with at least 4 skills each. That would mean creating events for each enemy and ability, so hundreds of lines.

tldr: I want to do:

fire object towards x (where x can vary)
apply damage to x (where x can vary)

To save hundreds of lines of events.

Do you want to set focus by some rule or randomly?

Randomly = pick random object condition.

By rule = set some id for object (object variable) and then pick object by his id as needed.

1 Like

Thank you. By rule. But can I select that rule or variable to attack it (move toward, apply damage, etc.), or just that object? Cause that’s the important part. I want to target some variable, not a specific object.

I don’t understand, what you exactly mean by “targeting variable”, but for example you can have array (or structure) of your objects in scene/global variables, there you can process what you need and then by result coming from this structure pick the object. For example I use structures like this:

So I can apply or work with variables over the structure and then apply it for player by id.

Also you can hold variables in objects, for example like this:

2 Likes

I want to target a [focused object], not the object itself, so that that object can vary and I can use the same event/order for multiple objects depending on which one is on focus.

I’m very new so I didn’t even know about arrays. I don’t know if it’ll help my case, but I’m going to test it.

Array and structures will serve me in the future, so thank you.

I don’t think it works for my current problem though. I want that Enemy_1 to be a variable slot, but it only let’s me select objects, not ids or variables.

Any way to do that, or even a trick to achieve the same result?

You have to have an “id” variable for each enemy and then store in some variable which enemy you have focused (for example “enemy_focused=3”. After that you can use it in your condition having “Variable id of Enemy = enemy_focused”. By doing this you will have picked focused enemy in your condition.

If you have more enemy objects, group them, give them all unique “id” variable and then do the same (I have described above) but with the group of objects.

If you don’t know about working with object groups, check some video tutorials.

1 Like

I think I got it to work by using a value, of a variable that’s in every object in a group, as a condition, then targeting that group, like you said. I’m gonna test it to be sure.

1 Like

You were absolutely right. Using the condition of the value, of the same variable in all objects in a group, works perfectly. Now I can set focus on an object by changing the value of that variable, then attack the group; I could even set focus on multiple objects if I wanted to in the future.

I can probably optimize the events lol, I did that quick, but it works and it’s gonna save me so much time and lines. Thank you so much.

You are welcome. And you can also probably simplify the code by making group of enemies and then go through them using for each object cycle.

1 Like