Expecting Keyword End

● ARCHIVED · READ-ONLY
Started by chungsie 8 posts View original ↗
  1. I know what the error message means. I have relocated the script to a brand new project, and I get the same results. However, I added the classes in one at a time to find where it breaks.

    Code:
    class Window_Coin < Window_Base
     
      def initialize(x,y,w,h)
        super
        @timer = 0
        @frame = 0
      end
     
      def draw_animation
        @sprite = Sprite.new
        case @frame
        when 0
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_1.png")
        when 1
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_2.png")
        when 2
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_3.png")
        when 3
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_4.png")
        when 4
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_5.png")
        when 5
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_6.png")
        when 6
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_7.png")
        end
        @sprite.x = 0
        @sprite.y = 0
      end
     
      def update
        super
        @timer += 1
        @frame += 1 if @timer == 60 || @timer == 120
        draw_animation if @timer == 60 || @timer == 120
        @timer = 0 if @timer == 121
        self.dispose if @frame == 6 && (@timer == 60 || @timer == 120)
      end
    end
    
    $title_on = true
    DataManager.init
    def updates
      Graphics.update
      Input.update
      $window2.update unless $window2.disposed?
    end
    
    
    $window2 = Window_Coin.new(100,Graphics.hieght/2,160,72) if $window1.disposed?
    updates while $title_on

    I have looked through it for missing end statements, and cannot find any. I'm sure it's a really simple fix. I am certain all the graphics are where they belong in the project folders. I've tried several workarounds, as soon that I make this window_coin it breaks. any help is much appreciated.

    EDIT

    I isolated the problems, now my entire sequence works. However, I'm having issues disposing the bitmaps for the sprites.

    Code:
    @sprite.dispose
        @sprite = nil
    this is my method for disposing the last sprite bitmap. according to all google searches this should destroy the last bitmap to allow me to create a new sprite instance with a new image.

    capture - 7-25-18.gif here is what it does currently. It's not disposing the bitmap even when the window is disposed.
  2. I've moved this thread to Script Support. Thank you.

  3. try calling

    @sprite.bitmap.clear
    @sprite.bitmap.dispose

    before disposing the sprite itself.

    Also if your goal is to dispose only the bitmap so that you can load another bitmap into the sprite, I suggest not disposing the sprite itself
  4. This part:
    Spoiler
    Code:
      def draw_animation
        @sprite = Sprite.new
        case @frame
        when 0
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_1.png")
        when 1
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_2.png")
        when 2
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_3.png")
        when 3
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_4.png")
        when 4
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_5.png")
        when 5
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_6.png")
        when 6
          self.contents.clear
          @sprite.bitmap = Cache.pictures("ci_7.png")
        end
        @sprite.x = 0
        @sprite.y = 0
      end
    Can be reduced to just this:
    Spoiler
    Code:
      def draw_animation
        @sprite.bitmap = Cache.pictures("ci_#{@frame+1}.png")
      end

    You have nothing in your window, so no need to clear it's contents.

    You keep creating a new sprite in that method on each new drawing. Those will be separate objects, and once you overwrite the instance variable holding them, any reference to these sprites are lost, which means you can't dispose them.
    When you tried @sprite.dispose, you disposed the last stored one, but the previous 6 were stuck on your screen forever due to the reasons mentioned above.

    Create that sprite upon the initialization of the window only. No need to make more, you will just change the bitmap of it.

    Also, don't mix sprites and bitmaps, they are separate classes. Sprites are used to display their assigned bitmaps on the screen. A bitmap alone can't do that.
    In most cases, you should dispose both of them, first the bitmap, and the sprite after.
    Undisposed sprites or incorrectly disposed ones can cause random crashes, so you should always get rid of them properly.
    You should dispose that sprite at the same place you dispose the window.

    This part:
    Spoiler
    Code:
      def update
        super
        @timer += 1
        @frame += 1 if @timer == 60 || @timer == 120
        draw_animation if @timer == 60 || @timer == 120
        @timer = 0 if @timer == 121
        self.dispose if @frame == 6 && (@timer == 60 || @timer == 120)
      end
    It checks for the same things over and over. Those checks are unnecessary, checking them once is more than enough since those values will not change after any checks made in that method.
    It should look like this instead:
    Spoiler
    Code:
      def update
        super
        @timer += 1
        case @timer
        when 60, 120
          @frame += 1
          draw_animation
          self.dispose if @frame == 6
        when 121
          @timer = 0
        end
      end
  5. I think this is probably better suited to 'Learning Ruby and RGSSx'

    [mod]Moving[/mod]
  6. I must not have been on my game today.

    I have correctly disposed the graphics. after testing I reduced the frame rate to 1/4 sec a frame.

    I can definitely clean up my methods @Sixth

    appreciate it guys

    update:
    ok so no I had to handle it more like this:

    Code:
    class Window_Coin_A < Window_Base
     
      def initialize(x,y,w,h)
        super
        @timer = 0
        @frame = 1
        draw_contents
      end
     
      def draw_contents
        @sprite = Sprite.new
        @sprite.bitmap = Cache.picture("ci_#{@frame}.png")
        @sprite.x = 120
        @sprite.y = Graphics.height/2
        @sprite.z = 400
      end
     
      def dispose_sprite
        @sprite.dispose
        @sprite.bitmap.dispose
        @sprite = nil
        self.contents.clear
      end
     
      def update
        super
        @timer += 1
        case @timer
        when 14
          dispose_sprite
        when 15
          @frame += 1
          @timer = 0
          draw_contents
        end
        self.dispose if @frame == 6 && @timer == 14
      end
    end

    this produced the desired result without error. had to modify the simplifications.
  7. You still needlessly create sprite objects. You can create that sprite in the initialize method of that window, no need to recreate it every time you want to change it's bitmap.

    In your update method, there is a 1 frame delay before displaying the next image. Not sure how it looks, but I imagine it is noticeable.
    If that delay was intended for some reason, than it's okay, otherwise you should display the next image right after you get rid of the previous one, in the same frame.

    You don't need to call self.contents.clear because there is nothing in your window.

    Spoiler
    Code:
    class Window_Coin_A < Window_Base
     
      def initialize(x,y,w,h)
        super
        @timer = 0
        @frame = 1
        init_sprite
        draw_contents
      end
     
      def init_sprite
        @sprite = Sprite.new
        @sprite.x = 120
        @sprite.y = Graphics.height/2
        @sprite.z = 400
      end
     
      def draw_contents
        @sprite.bitmap = Cache.picture("ci_#{@frame}.png")
      end
     
      def dispose_sprite
        @sprite.bitmap.dispose
        @sprite.dispose
      end
     
      def update
        super
        @timer += 1
        if @timer == 14
          if @frame == 6
            dispose_sprite
            self.dispose
          else
            @frame += 1
            @timer = 0
            @sprite.bitmap.dispose
            draw_contents
          end
        end
      end
     
    end
  8. Code:
    class Window_Coin_A < Window_Base
     
      def initialize(x,y,w,h)
        super
        @timer = 0
        @frame = 1
        sprite_init
        draw_contents
      end
     
      def sprite_init
        @sprite = Sprite.new
        @sprite.x = 120
        @sprite.y = Graphics.height/2
        @sprite.z = 400
      end
        
      def draw_contents
        @sprite.bitmap = Cache.picture("ci_#{@frame}.png")
      end
     
      def dispose_sprite
        @sprite.bitmap.dispose
      end
     
      def update
        super
        @timer += 1
        case @timer
        when 15
          dispose_sprite
          @frame += 1
          @timer = 0
          draw_contents unless @frame == 7
          self.dispose if @frame == 7
        end
      end
    end

    this was the solution I found works.

    capture - 7-27-18.gif

    some of the solutions do obey OOD which i ignored for this :p I just wanted to make something that works, and then make it pretty later. So thanks for that.