New random object from groups... How to add force

Hi guys I have a question about new created objects (from Object Groups). Using the following action “Among objects enemies, create object named “enemy” + ToString(Variable(enemy_id)) at Position 100;100”. In this way I successfully add to the game the object enemyX. My question is: after above action, how to add a “permanent force” to the just created object? How to get a reference to the just created Object?
Thanks in advance

You can use the group name if you want to effect all objects created from the same group.
If you want to effect only that specific object then I think you have no choice but to reference the object by it name. In case you don’t know the name because you create a random object or something then initialize an object variable for the object when create it and use that variable as a flag. Then add the condition to check the value of this variable so you effect only that specific instance or object that has that variable with that value, again you can use the group name here.

As an alternative to object variable, you can also try object linking.

Thanks ddabrahim for the reply. You guessed I created a random object. I’m a newbie and I’d like (like your suggestion) to initialize an object variable for the object when created.
After initialized a variable object, I guess I have to add the “permanent force” to the just created variable object, right?
Can you show me how to initialize a variable object with a randomly created object from “Object Groups”?
Thanks in advance

1 Like

After creating the object just simply use the action to set value of an object variable and for object name enter the group name.

Action:
Among object GroupName create object named “enemy” + ToString(Variable(enemy_id)) at Position 100;100”
Do = 1 to variable applyForce of GroupName

Because you have just created an object from the group in the same event, the group going to point to that specific object in this event.

After, by checking the value of ‘applyForce’ first If the value is 1, you can apply force only to that specific object. But as I mentioned if you want to apply force to ALL objects created from the group, then you don’t need to mess with the variable just use the group name. You need the variable only if you want to apply force only to this specific instance but no other.

Hope it helps.

Thanks ddabrahi. I have to add the “permanent force” only to just created object. I will follow your suggestion and keep you posted.
Thanks

Thanks again for the support ddabrahim. Following your suggestion I solved my issue. Here below a shot of my Events panel.

1 Like