设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 465|回复: 3
打印 上一主题 下一主题

[有事请教] 请高手看下脚本,为什么P1的地方不能执行

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3925
在线时间
254 小时
注册时间
2013-10-13
帖子
790
跳转到指定楼层
1
发表于 2023-10-8 21:10:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
#召唤方式:$scene=Bank_Scene.new

class Bank_Window < Window_Selectable
  def initialize
    @operate=["存钱","取钱","取消"]
    super(320-120,240,240,64+64)
    @[email protected]
    @column_max=3
    @index=0
    self.contents=Bitmap.new(self.width-32,self.height-32)
    refresh
  end
  def refresh
    for i in [email protected]
      self.contents.draw_text(i*64,0,64,32,@operate[i])
    end
#    self.contents.draw_text(300,0,64,32,$data_system.words.gold)
  end
  #--------------------------------------------------------------------------
  # ● 更新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 获取当前的行
    row = @index / @column_max
    # 当前行被显示开头行前面的情况下
    if row < self.top_row
      # 从当前行向开头行滚动
      self.top_row = row
    end
    # 当前行被显示末尾行之后的情况下
    if row > self.top_row + (self.page_row_max - 1)
      # 从当前行向末尾滚动
      self.top_row = row - (self.page_row_max - 1)
    end
    # 计算光标的宽度
    cursor_width = self.width / @column_max - 32
    # 计算光标坐标
    x = @index % @column_max * (cursor_width+16)
    y = @index / @column_max * 32 - self.oy
    # 更新光标矩形
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
end
class Window_Gold < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化窗口
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 128)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
    self.contents.draw_text(4,32,160-32,32,"身上的钱的数目")
  end
end
class Window_Gold_1 < Window_Base #yinhang窗口
  #--------------------------------------------------------------------------
  # ● 初始化窗口
  #--------------------------------------------------------------------------
  def initialize
    super(0, 240, 160, 128)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold_1.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
    self.contents.draw_text(4,32,160-32,32,"yinhang的钱的数目")
  end
end
class Game_Party
  attr_reader :gold_1 #yinhang的钱的数目
  alias old_initialize initialize
  def initialize
    old_initialize
    @gold_1=0
  end
  def gain_1_gold(n)
    @gold_1=gold_1+n
  end
  def lose_1_gold(n)
    @gold_1=gold_1-n
  end
end

class Bank_Scene
  def initialize(bank_index=0)
    @bank_index=bank_index
  end
  def main
    @b_window=Bank_Window.new
    @b_window.index=@bank_index  
    @gold_1_window=Window_Gold_1.new #yinhang的钱的窗口
    # 生成活动块
    @spriteset = Spriteset_Map.new
    @gold_window=Window_Gold.new
    @confirm_window=Window_Base.new(120, 88, 400, 64)
    @confirm_window.visible=false
   
    @yes_no_window = Window_Command.new(100, ["确定", "放弃"])
    @yes_no_window.x=120
    @yes_no_window.y=88+64
    @yes_no_window.visible=false
    @yes_no_window.active=false
   
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @b_window.dispose
    @gold_window.dispose
    @confirm_window.dispose
    @yes_no_window.dispose
    @spriteset.dispose
    @gold_1_window.dispose
  end
  def update
   
    @b_window.update
    if @b_window.active
      b_update
      return
    end
    if @yes_no_window.active
      confirm_update
    end
  end
  def b_update
    if Input.trigger?(Input::B)
      $scene=Scene_Map.new
    end
    if Input.trigger?(Input::C)
      if @b_window.index==0 #存钱
        @b_window.active=false
        @yes_no_window.active=true
      elsif @b_window.index==1#取钱
        @b_window.active=false
        @yes_no_window.active=true
      elsif @b_window.index==2#取消
        $scene=Scene_Map.new
      end
    end
  end
  def confirm_update
    @bank_index=@b_window.index
    @yes_no_window.active=true
    @yes_no_window.visible=true
    @yes_no_window.update
    @confirm_window.visible=true
    @confirm_window.contents=Bitmap.new(@confirm_window.width-32,
                                        @confirm_window.height-32)
    if @b_window.index==0
      @confirm_window.contents.draw_text(0,0,300,32,"想存钱?")
    elsif @b_window.index==1
      @confirm_window.contents.draw_text(0,0,300,32,"想取钱?")
    end
    if Input.trigger?(Input::B)
      $scene=Bank_Scene.new(@b_window.index)
    end
    if @yes_no_window.index==0
          if Input.trigger?(Input::C)
            if @b_window.index==0 #存钱
              if $game_party.gold>10000
                if @yes_no_window.index==0 #确定
                  $game_party.lose_gold(10000)
                  @gold_window.refresh
                  $game_party.gain_1_gold(10000)
                  @gold_1_window.refresh
                  $scene=Bank_Scene.new(@b_window.index)
                elsif @yes_no_window.index==1#放弃
p   1
                  $scene=Bank_Scene.new(@b_window.index)
                end
              end
            elsif @b_window.index==1#取钱
              if $game_party.gold_1>0
                if @yes_no_window.index==0 #确定
                  $game_party.lose_1_gold(10000)
                  @gold_1_window.refresh
                  $game_party.gain_gold(10000)
                  @gold_window.refresh
                  $scene=Bank_Scene.new(@b_window.index)
                elsif @yes_no_window.index==1#放弃
                  $scene=Bank_Scene.new(@b_window.index)
                end
              else
                return
              end
            elsif @b_window.index==2
              $scene=Bank_Scene.new(@b_window.index)
            end
          end
    else
      return
    end

  end
end
第一次写脚本,写的比较粗糙,特别是P1下面的$scene=Bank_Scene.new(@b_window.index)运行不了,点“确定”可以执行,为什么点“放弃”就执行不了?
在地图建立一个事件,运用脚本$scene=Bank_Scene.new,点回车,再点确定,可以运行,但是点放弃,就执行不了,不知道为什么?

Lv5.捕梦者

梦石
0
星屑
37849
在线时间
5424 小时
注册时间
2006-11-10
帖子
6549
2
发表于 2023-10-8 21:38:32 | 只看该作者
问:  你说要什么情况下才能做到 a == 0 且 a == 1 的呢?   

写条件分歧的时候也要注意上下层关系哦

点评

没看见上面还有个条件,明白了  发表于 2023-10-9 21:37
能解释一下吗?我用的是if和elsif。为什么说我要做到a==0且a==1呢?  发表于 2023-10-9 21:18
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-4 02:13

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表