New account registration is temporarily disabled.

[SCRIPTING] STUCK IN A WHILE LOOP

Posts

Pages: first 12 next last
Hey all, this one is definitely more in the code-funk territory and less in the high end RPG Maker, but I've been staring at this code for hours with no progress, and would be infinitely grateful if I could get a few extra eyes on it to see what might be the issue.

The code for this is basically going to loop through a list of missions, check them for certain variables, and add them to an accessible list that will get displayed for mission select. Note, before this function is called, I have a set of missions created with location 0 (So they should all get loaded), and all of them have been set to completed = 1 through a function inside them. However, when this code is ran, the entire thing locks up, meaning we're probably stuck in that while loop.

class Game_Interpreter
  def missionListCreate
    #Clean out the list of any old entries
    $mission_list.clear
    #Get the size of the mission array.
    @size = $mission.size
    #Where are we in the array
    @index = 0
    #Determines if location 1 is already full
    @loc1 = 0
    #Determines if location 2 is already full
    @loc2 = 0
    #Determines if location 3 is already full
    @loc3 = 0
    #Determines of location 4 is already full
    @loc4 = 0
    #Determines if we're done
    @done = 0
    #Determines current location in the $mission_list array
    @current = 0
    #Holder for the location of $mission.location
    @currentloc = 0
    #Start our loop
    while @done == 0
      #Check to see if the mission is available, which is value 1 on completed
      if $mission[@index].completed == 1
        #Set the location of the mission.
         @currentloc = $mission[@index].location
          #Check to see if location of the mission is 1
          if @currentloc == 1
            #See if any other missions have been there on this list
            if @loc1 == 0
              @loc1 = 1
              $mission_list[@current] = $mission[@index]
              @current += 1
            end
          end    
          #Check to see if location of the mission is 1
          if @currentloc == 2
            #See if any other missions have been there on this list
            if @loc2 == 0
              #Set location as used, add mission, increment location in mission 
              # list
              @loc2 = 1
              $mission_list[@current] = $mission[@index]
              @current += 1
            end
          end
          #Check to see if location of the mission is 1
          if @currentloc == 3
            #See if any other missions have been there on this list
            if @loc3 == 0
              #Set location as used, add mission, increment location in mission 
              # list
              @loc3 = 1
              $mission_list[@current] = $mission[@index]
              @current += 1
            end
          end
          #Check to see if location of the mission is 1
          if @currentloc == 4
            #See if any other missions have been there on this list
            if @loc4 == 0
              #Set location as used, add mission, increment location in mission 
              # list
              @loc4 = 1
              $mission_list[@current] = $mission[@index]
              @current += 1
            end
          end
          #check if there is no location set.
         if @currentloc == 0
           #Add mission, increment location in mission list
              $mission_list[@current] = $mission[@index]
              @current += 1
          end 
        end  
      #Make sure we're not going past the size of $mission  
      if @size == @index + 1
        @done = 1
      end
      #Make sure we're not adding more than 5 missions
      if $mission_list.size == 5
        @done = 1
      end
      #Increment where we are in $mission
      @index += 1
    end
  end
end


If any one has any ideas, please let me know, I know its probably something derpingly simple and I just can't see it because I wrote it :P
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
At the end of the code, still inside the while loop but outside anything else (after you increment the index basically) write "puts @done", run it and tell me what the console output is.

Also, where are you calling this method from?
Did so, and it basically did this endlessly.



I'm calling this from an event in game, after doing some test setting (setting all mission completed's to 1 so they can be read), and before calling a scene window to have the player select them. Here is the snippet from the event:

$mission[0].finish(1)
$mission[1].finish(1)
$mission[2].finish(1)

missionListCreate

SceneManager.call(Scene_MissionSelect)

The $mission adjusts, mission list create, and mission select are different script lines, but contiguous, if that matters.

Edit: If its any help, during my testing, I commented out all the ifs except for the one if ... == 0, and got the same results.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
The event isn't parallel process or autostart is it?
Nope, its set to action button.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Would you be able to zip up your project and upload it somewhere so I can have a look?
Oh wow, I must have really borked up the code :(

https://drive.google.com/file/d/0B4_pL7t6QETEaDIzWGVCbFo1dWs/view?usp=sharing

There's the link to the compressed project. Its in VXACE, lemme know if I need to include the RTP with it.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Not necessarily, but I find it way easier to debug someone else's code when I have it in front of me and can add debug statements where I need them without having to communicate the requirement through the person who needs help. :P Give me 10 minutes.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Not necessarily, but I find it way easier to debug someone else's code when I have it in front of me and can add debug statements where I need them without having to communicate the requirement through the person who needs help. :P Give me 10 minutes.

Edit: Got it. I'm not 100% sure why, but because you have your call to missionListCreate in a separate script call in the event it's causing an infinite loop. If you put all of the event script in one "box" it works fine.
Oh, I had no idea that was any different. Weird little 'should work fine's keep tripping me up :P Thanks so much for taking the time to look at it.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Any time bud, I'm intrigued by this and will be looking into it further to see if I can figure out why it did that.

Edit: ROFL, and it's a doozy. You're using an instance variable called @index in missionListCreate, which is a method of Game_Interpreter...which already has its own @index instance variable, which tracks which event command is currently being processed. You're basically overriding the standard event processing and completely breaking the way events work when you use this. You should be able to fix it by changing @index to something like @mission_index so it's unique.
Gah! I keep overwriting variables and definitions without realizing it. I hate having overly long variable/class names, but it looks like I'll need to start doing that, just so I don't overwrite stuff in the base classes.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Why not expand it into its own Game_Mission class instead of extending interpreter?
I might, if things get too complicated with it, but as it stands I'm about to do some testing, and if all works out, the mission things and their checks are basically done. Albeit I'll clean up the selection screen a hell of a lot more, and eventually add a party select function to it, but those will be scenes separate.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Why are you using instance variables for everything anyway? Presumably you're not using these variables elsewhere in the code, so you could just make them local.
I'm sorry, my knowledge of Ruby is about five days old, so I don't know what the difference is between them, nor which is which when I'm looking at the code. Most of what I've scraped together I've either learned by looking at your tutorials and moving things around, or have dug around in the game code itself to find specific calls to use.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
Do you want me to make it a bit more efficient for ya?
I mean, I know its terribly inefficient, but I hate to ask anyone else to fix up my mistakes (more than I already have on here that is).
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
I know you weren't asking, that's why I'm offering. I like helping people to improve their scripts. ^_^
Well, if you're offering, sure, at least I'll be able to reference it for later scripts so I don't keep making smelly code.
Pages: first 12 next last