///this code is in the object
var inst = instance_place(x, y, obj_soldier); //or some other code to get instance id
if (inst != noone) {
if (soldier_count >= inst.soldier_count) && (merge_possible) {
inst.merge_possible = false;
soldier_count += inst.soldier_count;
instance_destroy(inst);
}
}
if collision_with_enemytown = 0
{
var inst = instance_place(x, y, obj_banner); //or some other code to get instance id
if (inst != noone) {
if (banner_soldiers >= inst.banner_soldiers) && (merge_possible) {
inst.merge_possible = false;
banner_soldiers += inst.banner_soldiers;
instance_destroy();
}
}
}
my code was written assuming that both instances would be instances of the same object. If that is not true, you will need to put the important variables in all possible objects. This code says that obj_banner does not have a variable named merge_possible. However, if your code has some other way of figuring out who will merge, then you probably don't even need that variable. Again, my code will only work for very specific situations. The important parts are of it are:Thnx samspade
At the moment I have a banner instance with within a variable called banner.soldiers.
This banner instance is standing next to a city with another variable: collision_with_enemytown = 1. When the banner instance gets created this var is set to 0. It then moves to the city and find the other banner standing there. If its 0 then it will destroy itself. So its supposed that the banner instance that has the variable: collision_with_enemytown = 1 will get the soldiers. this, because that banner is in a fight with that city.
I have this now:
But I get this error:Code:if collision_with_enemytown = 0 { var inst = instance_place(x, y, obj_banner); //or some other code to get instance id if (inst != noone) { if (banner_soldiers >= inst.banner_soldiers) && (merge_possible) { inst.merge_possible = false; banner_soldiers += inst.banner_soldiers; instance_destroy(); } } }
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Eventobj_banner
for object obj_banner:
Variable obj_banner.merge_possible(100169, -2147483648) not set before reading it.
at gml_Object_obj_banner_CollisionEvent_36_1 (line 6) - if (banner_soldiers >= inst.banner_soldiers) && (merge_possible) {
############################################################################################
if collision_with_enemytown = 0
{
var inst = instance_place(x, y, obj_banner); //or some other code to get instance id
var merge_possible = true
if (inst != noone) {
if (banner_soldiers >= inst.banner_soldiers) && (merge_possible) {
inst.merge_possible = false;
banner_soldiers += inst.banner_soldiers;
instance_destroy();
}
}
}
I did and it does. But likely it relies on assumptions which are different. However, one important change in the code you typed could be causing the problem. You have instance_destroy, rather than instance_destroy(inst). The difference being your code will destroy the instance that gets the additional soldiers rather than the instance that gives the additional soldiers. Additionally, by adding var merge_possible = true you have removed the error message but also made the check pointless as it will always evaluate to true if set two lines before being called (rather than in the create event). These are obviously problems, but might not be the main ones. Based on your description, I wonder if collision_with_enemytown == 1 shouldn't be the conditional to check for as you want that object to receive the soldiers. Also, like I said, if you already have a means of determining who gets the soldiers then you probably don't need the >= merge possible check.They are both instances of the same object. Like I told in my second message.
I added the merge_possible as a var:
And then no error, but the second instance gets destroyed and nothing happens to the soldiers.Code:if collision_with_enemytown = 0 { var inst = instance_place(x, y, obj_banner); //or some other code to get instance id var merge_possible = true if (inst != noone) { if (banner_soldiers >= inst.banner_soldiers) && (merge_possible) { inst.merge_possible = false; banner_soldiers += inst.banner_soldiers; instance_destroy(); } } }
I did figure out the id of the instance with this:
banner = id
After that nothing seems to work.
The determering is that the instance with the variable collision_with_enemytown = 1 gets the soldiers.
use the instance id to add soldiers and destroy the instance. This seems impossible. I do not ask help for nothing. I tried several things.
Your code does not work, sorry.
Try it out and you'l see for yourself.
if collision_with_enemytown == 1
{
var inst = instance_place(x, y, obj_banner);
if (inst != noone) {
banner_soldiers += inst.banner_soldiers;
instance_destroy(inst);
}
}