R
Razazke
Guest
I recently downloaded the 2.3 beta, and have been trying to convert object data into structs. Here are some examples:
Player object Create event:
Bullet object collide event
Inventory script(because I reference it in Player)
Compilation is fine, for the most part, and I can "fire" a bullet object, but when colliding with the wall, I receive an error of
Can you not reference a struct like a typical class? Also tried to make a constructor in the struct, and that failed too, when trying to instantiate a new instance of the struct. Thanks for the help.
Player object Create event:
GML:
PlayerStruct = {
__player_life : 0,
__player_attack : 0,
__player_defense : 0,
__player_critChance : 0,
__PlayerInventory : Inventory_obj(),
setPlayerHealth : function(value)
{
__player_life = value
}
};
//function Player_obj() constructor
//{
//__player_attack = 1;
//__player_life = 10;
//}
show_debug_message("We are in the game")
function getPlayerHealth()
{
return __player_life;
}
GML:
if(instance_exists(player))
{
PlayerStruct.setPlayerHealth( getPlayerHealth())
instance_destroy()
if(getPlayerHealth<=0)
{
instance_destroy(player)
instance_destroy()
}
}
else
{
instance_destroy();
}
GML:
Inventory = {
size : 0,
Inventory: function() constructor
{
size +=1;
},
getSize : function()
{
return size();
},
}
Compilation is fine, for the most part, and I can "fire" a bullet object, but when colliding with the wall, I receive an error of
Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Step EventWall
for object bullet:
Variable bullet.PlayerStruct(100030, -2147483648) not set before reading it.
at gml_Object_bullet_Collision_Wall (line 5) - PlayerStruct.setPlayerHealth( getPlayerHealth())
############################################################################################
gml_Object_bullet_Collision_Wall (line 5)
Can you not reference a struct like a typical class? Also tried to make a constructor in the struct, and that failed too, when trying to instantiate a new instance of the struct. Thanks for the help.
Last edited by a moderator: