GML Help

I am making a simple game in GML. I have the following code in a step event of an object meant to generate no more than 10 enemies:
if (isEnemySpawnable == true){

    xc = random (1500);
    yc = random (900);
    
    for (e = 0; e == 0; e+= 1){
    
        instance_create(xc, yc, obj_enemy);
    
    }

}

else {



}


if (eCount >= 10){

    isEnemySpawnable = false;

}


TheisEnemySpawnable variable has already been declared. When I run the game, I get the following error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object obj_enemy_generator:

Push :: Execution Error - Variable Get -1.isEnemySpawnable(100002, -1)
 at gml_Object_obj_enemy_generator_Step_0 (line 1) - if (isEnemySpawnable == true){
############################################################################################


Please tell me what is wrong.

Comments

  • Could you post the gml_Object_obj_enemy_generator_Step_0 (line 1) code with code lines?
  • That posted code is the code in the step event of the obj_enemy_generator. I probably should have been more specific.
  • I think it's giving the error because it's going into a negative value. Not sure though. Sorry that I can't help :/ I can read the code perfectly fine, but I just can't solve the issue >_<
  • This is the error:
    for (e = 0; e == 0; e+= 1) 
    

    Should be:
    for (e = 0; e < 10; e+= 1)
    

    At least, that is the error you'd have in C - I'm not sure about GML syntax.
  • That seemed to fix that error. Now I get the following error :
    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of  Step Event0
    for object obj_enemy_generator:
    
    Push :: Execution Error - Variable Get -1.isEnemySpawnable(100002, -1)
     at gml_Object_obj_enemy_generator_Step_0 (line 1) - if (isEnemySpawnable == true){
    ############################################################################################
    


    Here is that code again:

    if (isEnemySpawnable == true){
    
        xc = random (1500);
        yc = random (900);
        
        for (e = 0; e < 10; e+= 1){
            instance_create(xc, yc, obj_enemy);
        
        }
    
    }
    
    else {
    
    
    
    }
    
    
    if (eCount >= 10){
    
        isEnemySpawnable = false;
    
    }
    


    Can you help me with that?
  • You ARE a well-spring of these. ;) LOL

    "true" and "false". Are they OK being lowercase?. In C, we make such things #define values, and use UPPERCASE to distinguish them. Should your true be TRUE, and your false be FALSE?

    The error message is pointing at line #1, so I'm thinking it must be a spelling error or the true (lowercase), that it doesn't like.
  • I tried it, and it is not the case of the true and false. Do you have any other ideas?
  • Is enemySpawnable a variable or is it a function that requires parameters? In that error message, it looks like it's a function, and here, it needs parameters - two of them, probably.
  • Adak wrote:
    This is the error:
    for (e = 0; e == 0; e+= 1) 
    

    Should be:
    for (e = 0; e < 10; e+= 1)
    

    At least, that is the error you'd have in C - I'm not sure about GML syntax.

    I'm so stupid for not seeing that *FacePalm* :'(
  • Proxi wrote:
    I'm so stupid for not seeing that *FacePalm* :'(
    Nah, you were just giving me a chance to look smart! Thanks! ;)
  • Here is the code from the create event of a start object that I have to declare some variables (including isEnemySpawnable):

    eCount = 0;
    
    isEnemySpawnable = true;
    
    score = 0;
    
  • There are a whole series of GML tutorials on YouTube:
    http://www.youtube.com/watch?v=zbBAAW0Kel8
    for example.

    I want you to watch the video's in order, and see what you can learn. Also, try asking them on-line about this error.

    Also, there is a GM forum - I'm not positive it's the same Language or not. But find a GML forum, and repeat your question to them. Google is your friend.

    The only other thing I can suggest, and it's a stretch of great dimension, is that your enemy is previously of a type that is not spawnable, somehow. Try removing that line of code, and seeing if it will compile successfully, without it.

    If so, review your enemies characteristics, to find the conflict.

    Good luck.
  • Adak wrote:
    Nah, you were just giving me a chance to look smart! Thanks! ;)

    You Sir are obviously smarter than me in programming with your experience :D
  • Proxi wrote:
    You Sir are obviously smarter than me in programming with your experience :D

    Well maybe, but I'm really second rate as a Zombie Prepper. :rolleyes:
Sign In or Register to comment.