Window won't close fully, and Scene won't animate properly

● ARCHIVED · READ-ONLY
Started by MysteryMan23 10 posts View original ↗
  1. I'm working on a Mastermind minigame for my current project, and I'm having a problem.

    I have a "Give Up" function, which ends the game early. It does this by running an end_game() function. Here's the relevant code:

    Class Window_SecretCode < Window_PegBoard def reveal_code @display_symbol.each do |display| display = true Worlds::MastermindReveal.play 60.times { Graphics.update } end endendClass Scene_MasterMind < Scene_Base def end_game(victory) @decoder_window.deactivate @secret_code_window.reveal_code if victory Worlds::MastermindWin.play else Worlds::MastermindLose.play end @play_again_window.open @play_again_window.activate end def on_abort_ok @abort_game_window.deactivate @abort_game_window.close end_game(false) endendNow, my problem is, whenever the game ends, the program is supposed to reveal the secret code, one symbol at a time. However, whenever I select "Give Up" (which triggers on_abort_ok), the window fails to close all the way, and the secret code fails to show up.

    So, what's happening here? Any ideas? Thanks.
  2. window#close need a time(3-5 frames) before the window completely closed, but before the window succesfuly closed the code, call the reveal_code method, which is trapping the system to only updating at that block of code(if you know what I mean). Now I can see you add Graphics.update in that method, but it's not helping because @abort_game_window.close is not inside that block of loop(means already not executed).

    Try this : @abort_game_window..openness = 0 instead @abort_game_window.close

    It's actually will not play the closing animation, but I believe it will comlpetely close the abort window, if you insist to play the closing animation, there are several ways to do it though.


     
  3. @BoluBolu: I'd honestly prefer to have the close animation happen. It's just cleaner that way. So, what are some of the ways to do that?

    By the way, I have the code showing up properly. Basically, my old block was something like this:

    my_array.each do |element| element = fooendHowever, none of the actual elements of my_array were changing to foo. I replaced that block with one like this:

    my_array.size.times do |x| my_array[x] = fooendIt appears that "each" blocks don't work as well for altering array elements. I have no clue why.
  4. Here's some fast way to do it(hopefully work) :

    def on_abort_ok @abort_game_window.deactivate loop do break if @abort_game_window.close? @abort_game_window.close Graphics.update end end_game(false)endI think that should work like what you want, but that's not the very best way.

    To explain #each method, it's a bit hard, but each never change the object, it just let you do anything with it.
    For that case what you want is probably #map method, though I don't know what happen with your array so I don't really know what you want.


     
  5. @BoluBolu: No, your method doesn't work. I don't know why, but the game just freezes. It's definitely something to do with the loop, as applying it to my other methods caused them to freeze the game, as well. F12 still works, though. Tracing the method, it definitely goes through the whole loop each time, it's just nothing's happening.

    As for the each method, I've already worked out the issues with that. But thanks anyways, for both your solutions.

    EDIT: I know this goes a little beyond the range of my topic, but I'm having a little trouble accurately counting the cows for my game. My current method is this:

    def calculate_cows cows = 0 marks = [false, false, false, false] for i in 0..3 for j in 0..3 unless i == j || marks[j] == true if @code_symbols == @guess_symbols[j] && !(code_symbols[j] == @guess_symbols[j]) cows += 1 marks[j] = true break end end end end return cows endHowever, this formula has a way of detecting phantom cows that should not exist. I'm not 100% sure why, and any assistance in this area would be appreciated. Thanks.
  6. Sorry for the late reply, need to sleep :p
    Well as expected that method I gave not worked because I forgot the way #close method work, try this method instead(this should work),
     

    def on_abort_ok @abort_game_window.deactivate loop do break if @abort_game_window.openness <= 0 @abort_game_window.openness -= 40 Graphics.update end end_game(false)endAs for your cows counting, I'm here or somebody here will have a very hard time helping you because we don't know what exactly happened in there. I mean, what is @code_symbols and @guess_symbols, how both variables works? Also what is mark =[false, false, false, false] why is that, and what happen with it?and that break also make me a little confused, why breaking for the first time for loop countering true?
    The worst thing is this

    unless i == j || marks[j] == trueif @code_symbols == @guess_symbols[j] && !(code_symbols[j] == @guess_symbols[j])I really failed to understand, sorry call me a dumb.

    Okay let's make it simple, what are you trying to achieve with that method? To be precise, what are you tring to accomplish, explain it in short story maybe?


     
  7. It appears that "each" blocks don't work as well for altering array elements. I have no clue why.
    Because each simply gives you the values on each element of the array. Also, .each actually iterates thru the array and being able to edit the contents of the array while iterating it can lead to huge problems, so it also serves as a protection.
  8. @BoluBolu: Basically, I'm doing a typical (if simplified) Mastermind game. The computer creates a code of four symbols, and you have to guess the code. Every time you do so you get feedback as to the following:

    • How many matching symbols are in the right position: I'll call these "bulls".
    • How many matching symbols are in the wrong position: I'll call these "cows".
    Basically, my problem is that I need a function to find the cows. Every function I have tried so far has had some flaw which caused it to miscount the cows. So, I need a function that will always detect the cows properly.

    With the method I showed off in particular, my algorithm was:

    • For each entry x of Code Symbols (hence @code_symbols)For each entry y of Guess Symbols (hence @guess_symbols)If y's position is the same as x's position, or y is marked, do nothing. (That is, unless i == j || marks[j] == true, do the following)
    • Else, if x and y's values are the same, and the value of Guess Symbols in y's position is different: (That is, if @code_symbols == @guess_symbols[j] && !(code_symbols[j] == @guess_symbols[j]))Increase cows by one
      [*]Mark off entry y so that it won't be detected again
      [*]Break the loop

    Thing is, this formula often outputs cows incorrectly; it would find them where there were none. Here's an example:

    BuggyMastermindGame.png

    As you can see, the game counts one bull and one cow, even though the guess is all reds and there's only one red in the code. Clearly, the cows are being counted wrong; the bull count is correct.

    I'm at least considering the idea of scrapping the method I was given in favor of something better. What do you think?
  9. Sorry for the late reply I just watching a movie and got back just now.
    Alright, I never cross a game like this before, but as I try to understand, the first line should give a feedback output 1 correct and 3 false?
    If the feedback is only that I think it's not that hard.

    Here's the algorithm that will do what you want(hopefully it explained to you), keep in mind that you need to implement it yourself in your game. I just give some logic and the better way to do this.

    the_code = [ 1, 2, 3, 4]guessed_code = [2, 1, 3, 4] <= This is examplebull = 0cow = 0result_array = []4.times do |i| result_array.push(the_code <=> guessed_code)end result_array.each do |i| bull += 1 if i == 0 cow += 1 if i != 0 endthe_code is the code that player must guess in order he/she wins the game.

    guessed_code is the code that player has entered.

    NOTE : I use integer 1,2,3,4 for example.

    bull is variable that will store value integer how many code are the player entered not just correctly but also in the correct line(if you know what I mean).

    cow is variable vice versa to bull

    Well, I hope it's eplained to you clearly.
  10. @BoluBolu: Not quite what I was looking for. I'm not looking for the number of symbols that are incorrect; I'm looking specifically for those symbols that are in the code, but misplaced.

    Still, I think you're on the right track. I think counting bulls and cows simultaneously may work better than counting them separately. At least, I'll be able to better tell what I'm doing.

    Thanks for your help. I'm not sure I could have gotten this game how I wanted it without you! :)