wtf why isn't this working

Posted by NeutralReiddHotel on June 7, 2015, 12:36 a.m.

since i don't frequent the GMC anymore or yoyogames i'd figure i ask here

why this no work

   if (heal_step=0) {
      heal_number=-1;
      i=0;
      for (i=0;i>=6;i+=1) {
         if (slot[i+1,0]!=0) { // meaning in slot i, is there a species sitting there?
            heal_number+=1;
         } else { // if there isn't, end the loop
            i=6;
         }
         show_message("hey look at me i work");
      }
      heal_monitor=0;
      heal_ball_number=0;
      draw_heal_animation=true;
      heal_counter=30;
      show_message(string(heal_number));
   }

in specific, this part:

      for (i=0;i>=6;i+=1) {
         if (slot[i+1,0]!=0) { // meaning in slot i, is there a species sitting there?
            heal_number+=1;
         } else { // if there isn't, end the loop
            i=6;
         }
         show_message("hey look at me i work");
      }

running this gives me nothing. i fear i simply don't know how to run for statements, but I did one in another part of my game recently, and i have no idea why this doesn't work.

here's the video running:

so like, the video shows that the show_message("hey look at me i work"); part never runs, but the show_message(string(heal_number)); does. my goal is to make the heal_number equal the number of pokemon in my party, in this case, 2.

slot[0,0] is slot 0, and species id. slot 0 holds nothing

slot[1,0] holds charmander

slot[2,0] holds ghost.

what do i do now? i'm confused and i've spent weeks breaking my head with one line of code and i'm trying to avoid it this time if i can, because something tells me this is a SUPER simple fix im simply not seeing at the moment.

without this, healing a pokemon in my game will forever look retarded :(

Comments

spike1 9 years, 6 months ago

I think this part:

for (i=0;i>=6;i+=1) {

should be this:

for (i=0;i<=6;i+=1) {
, otherwise the for loop condition is never true. Hope that works :).

NeutralReiddHotel 9 years, 6 months ago

thanks spike1! that worked like a charm! :) I knew there was a simple fix i couldn't see because i was stuck on tunnelvision! ahh man u saved me hours man.

OBELISK 9 years, 6 months ago

imagine there's no heaven

Alert Games 9 years, 6 months ago

Saw one of your other videos with the music, and it sounds amazing. I haven't kept up with your project at all, but I would play it when its closer to done

LAR Games 9 years, 6 months ago

Are you running Game Maker on linux? You can do that now?

LAR Games 9 years, 6 months ago

That's what I was thinking at first, but I remember trying to use it with wine and games not being able to run.

Then again, that was a very long time ago…

LAR Games 9 years, 6 months ago

Wow. That's pretty neat. I guess there's a new platform I can test it on now. :P

Polystyrene Man 9 years, 6 months ago

howdy! i noticed a couple other issues with your code

first, this is redundant:

i=0;

because you declare the variable i in your for loop. you can just get rid of that line.

second, i don't think this is doing exactly what you want it to do

} else { // if there isn't, end the loop
    i=6;
}

the way you have it set up here, the loop will break ("exit" or "stop") as soon as a slot is not 0. this means that if the first slot is not 0, it will not evaluate any of the remaining slots. if that's your intended behavior, then you should instead use a break statement:

if (slot[i+1,0]!=0) { // meaning in slot i, is there a species sitting there?
    heal_number+=1;
} else { // if there isn't, end the loop
    break;
}

however– it doesn't look like this is accomplishing exactly what you want it to do. imagine a situation where there's no element at position 2, but there IS an element at position 3. that element at position 3 won't be counted because the loop will have ended. instead, you should remove the else block:

if (slot[i+1,0]!=0) { // meaning in slot i, is there a species sitting there?
    heal_number+=1;
}

you're still not adding to heal_number unless there's an element at the position i, but now you're counting all slots, even if one happens to be empty along the way.

final note: instead of spending weeks "breaking your head" trying to get things to work, i recommend posting here - teaching people to code is part of my job and something i enjoy a whole lot

Alert Games 9 years, 6 months ago

Also put the curly braces on a new line after the statement conditions? … plz…

Moikle 9 years, 6 months ago

Alert, his way is the same as mine. It is an actual proper convention to do it EITHER of those ways, as long as you are consistent.

I prefer it because it means the if statement is the last thing before the indented line, and matches straight up to the closing brace. I find it easier to scan my eyes down this way.

That and it saves on the number of lines you use, fit more on the screen.

} else { 

Except I don't do that

Edit: hold the fuck up for a second i only copied one line and 64d managed to find the whole block that code came from if you click the red arrows in the top right.