• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

With statement not working? (SOLVED)

S

ShuaTheGreat

Guest
Hello everyone, I had this one issue for a while and can not figure out what the problem is.
Code:
if txt == Answer
{
 with (Targeted object)
 {
  destroy = true
 }
}
I insert this into a "Press Enter" event and nothing happens.
I have tested to see if all the variables are the correct values and they are.
I have put inside each Targeted object where if "destroy" is true, then it will destroy itself, but it does not work.
Help.
Sorry if this is simple and I'm just stupid :p
 
M

MishMash

Guest
First of all, we'll need to see the code in the Targeted object, otherwise, its hard to identify where the problem is.
Stick a show_debug_message("Destroying target object: "+string(id)); inside the with statement to verify that it is actually running.

Naturally, assuming if what you say is true, and the variables are the correct value, then the issue isn't in the with statement, but rather the code that checks if destroy is true and destroys the object.
 

Jezla

Member
Why don't you just put the instance destroy call inside the with statement, if all you want to do is destroy the instance when txt == answer?

Code:
if (txt == answer)
     {
          with(target)
               {
                     instance_destroy();
               }
     }
Then if it doesn't work, you only have to check if one condition is being met, rather than hunting down two conditions in two objects.
 
S

ShuaTheGreat

Guest
Ya, having
Code:
if txt == Answer
{
 with (Number_Generator)
 {
  destroy = true
  show_debug_message("Destroying target object: "+string(id));
 }
}
doesn't work.
I used the draw event to show whether the variables were the right values, and from that, they were.
Wouldn't this work?
Inside the step event of the object which carries the guess of the user
Code:
txt_str = string_digits(txt)
txt_real = real(txt_str)
Inside the step event of the object which is comparing the values
Code:
if instance_exists(Obj_Answer)
{
 txt = Obj_Answer.txt_real
}
 

klys

Member
Sometimes when you are having a logic error game maker is not able to tell you which is the problem and instead it try to use generic variables values and that make the games on this engine to behave in wierd ways.

The best here is to debug all variables using variable_instance_exists and showing also their values with show_debug_message
 
S

ShuaTheGreat

Guest
variable_instance_exists doesn't seem to be a function.
 
G

Guy_Typing

Guest
Hello everyone, I had this one issue for a while and can not figure out what the problem is.
Code:
if txt == Answer
{
 with (Targeted object)
 {
  destroy = true
 }
}
I insert this into a "Press Enter" event and nothing happens.
I have tested to see if all the variables are the correct values and they are.
I have put inside each Targeted object where if "destroy" is true, then it will destroy itself, but it does not work.
Help.
Sorry if this is simple and I'm just stupid :p
Do not post pseudo code considering the problem could be the code itself. The more information you give us that is accurate the more we can help you. Other than that put a show_message("destroyed"); right after destroy=true and see if it flags(if the message pops up) and if it doesn't you aren't even making it to that point.
 

Nux

GameMaker Staff
GameMaker Dev.
have you checked to see if the target object is present before using the with statement? if the desired object doesn't exist, then the with statement will just silently exit without executing any code nested within it. Alternatively, your conditional statement may not even be getting executed, which is a whole different problem.
 
S

ShuaTheGreat

Guest
Sorry guys for wasting your time, I figured it out. One problem was a typo, but there were a few other problems that I just figured out.:p
Yes, I check if the object exists before using the with statement, that was a problem that I was having though.
 
G

Guy_Typing

Guest
Sorry guys for wasting your time, I figured it out. One problem was a typo, but there were a few other problems that I just figured out.:p
Yes, I check if the object exists before using the with statement, that was a problem that I was having though.
Okay, cool! Glad to hear it. Be sure to mark the post as solved by editing the title up top and placing (SOLVED) with the rest of the title. Thanks.
 
Top