SOLVED Receiving "unable to convert string to int64" error.

flyinian

Member
I'm getting the error, "unable to convert string "Count 2" to int64" when I run the below code.

I'm just learning arrays so, I don't fully understand how they operate yet.

I am trying to create an array that checks to see if all the items in the array returns all zeros or not.


GML:
var array;
var enemy_key1 = array[choose("Count 1", "Count 2", "Count 3")];
var enemy1 = EnemyList[? enemy_key1];

var check = false;
for(var i = 0; i <= 0; ++i){
if (array[i] == true){
check = true;
}
}
if(check == true){
    
    noenemy = true;
    
};

if(noenemy = true){
show_debug_message("no enemy numbers to deduct");
exit;
}
else
{
show_debug_message("Enemy exists");

enemy1 -= EnemyList[? "totalcountdifference"];
EnemyList[? enemy_key1] = enemy1; 


show_debug_message("Enemy Count adjusted");   
};
};
};
Thank you.
 

Nidoking

Member
var array;
var enemy_key1 = array[choose("Count 1", "Count 2", "Count 3")];
I really don't know what you think this should do, but it doesn't do that. It declares an undefined variable, and then tries to use a string (the result of choose) as an index into that variable, which as has been established, is undefined. I know you said you're just learning arrays, but if you haven't read the Manual pages on how they work or used any tutorials at all, you have a lot more learning to do.
 

flyinian

Member
Is EnemyList a ds_map?
I really don't know what you think this should do, but it doesn't do that. It declares an undefined variable, and then tries to use a string (the result of choose) as an index into that variable, which as has been established, is undefined. I know you said you're just learning arrays, but if you haven't read the Manual pages on how they work or used any tutorials at all, you have a lot more learning to do.

Not sure if this is any better but, I no longer get the error message. However, I am still getting the issue that I had before implementing this code which may be a different future post.

GML:
var array = [];
array = [choose("Count 1", "Count 2", "Count 3")];
var i = 0;
var enemy_key1 = array[i];
var enemy1 = EnemyList[? enemy_key1];

var check = false;
for(var i = 0; i <= 0; ++i){
if (array[i] == true){
check = true;
}
}
if(check == true){
    
    noenemy = true;
    
};

if(noenemy = true){
show_debug_message("no enemy numbers to deduct");
exit;
}
else
{
show_debug_message("Enemy exists");

enemy1 -= EnemyList[? "totalcountdifference"]; // We edit enemy, but the version in the map isn't yet updated!
EnemyList[? enemy_key1] = enemy1; // Store the modified version back into the map! It is now updated!


show_debug_message("Enemy Count adjusted");   
};
};
};
 

Nidoking

Member
I still think you either don't know what an array is, or what the choose function does. Those are both listed in the Manual. What you've done here is created an array with one element, which is technically known as "a variable but you have to put [0] on it with no benefit whatsoever, why would you do this".

What it looks like you're trying to do is something that could be done without an array. I assume your intention is to convert that into using an array, so that you can learn arrays? If so, try writing the non-array version first, so you can see the working solution. Then, try to figure out how to construct the array of inputs you want. (SPOILER: It's much, much, MUCH simpler than whatever you're trying to do, and the function "choose" appears nowhere in any correct answer.) Finally, you can put all of the pieces together.
 
Top