幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1424|回复: 1

[RM2K&2K3] [求助]filetest.exist失灵的问题

[复制链接]

64

主题

103

帖子

627

积分

⑤进阶

积分
627
发表于 2007-7-20 16:34:15 | 显示全部楼层 |阅读模式
我的filetest.exist?()似乎失灵了,他全返回false,即使文件存在.
他是不是只能检测*.rxdate的文件?
  1. #==============================================================================
  2. # ■ Scene_UnderTitle2
  3. #------------------------------------------------------------------------------
  4. #  处理标题画面的类的类,用于用户的登陆。
  5. #==============================================================================
  6. class Scene_UnderTitle2
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     # 执行过渡
  12.     Graphics.transition
  13.     # 作成
  14.     if $game_system.timescount == 0
  15.     input_user_name
  16.     else
  17.     do_requirements
  18.     end
  19.   end
  20.   #--------------------------------------------------------------------------
  21.   # ● 输入用户密码
  22.   #--------------------------------------------------------------------------
  23.   def input_user_name
  24.     $game_system.timescount = 1
  25.     $scene = Scene_PassWord.new
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # ● 达成要求
  29.   #--------------------------------------------------------------------------
  30.   def do_requirements
  31.     $game_system.timescount = 0
  32.     case $User_Doing
  33.     when 1
  34.       log_in_the_account
  35.     when 2
  36.       create_a_new_account
  37.     end
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● 登陆帐户
  41.   #--------------------------------------------------------------------------
  42.     def log_in_the_account
  43.       @user_name2 = $game_system.user_name
  44.       @pass_word2 = $game_system.pass_word
  45.       filename= make_password_file_name(@user_name2)
  46.       p filename
  47.       i=  FileTest.exist?(filename)
  48.       p i
  49.       if i
  50.        @window_information=Window_Reminder.new(1)
  51.        for i in 0..150
  52.        Graphics.update
  53.        end
  54.        @window_information.dispose
  55.        $scene=Scene_UnderTitle.new
  56.        return
  57.       else
  58.        file =File.open(filename,"rb")
  59.        read_password_file(file)
  60.        file.close
  61.       if @pass_word == @pass_word2
  62.        @window_information=Window_Reminder.new(3)
  63.        # 弹出框子
  64.        for i in 0..150
  65.        Graphics.update
  66.        end
  67.        @window_information.dispose
  68.        $scene=Scene_Title2.new(@user_name)
  69.       else
  70.        @window_information=Window_Reminder.new(2)
  71.        # 弹出框子
  72.        for i in 0..150
  73.        Graphics.update
  74.        end
  75.        @window_information.dispose
  76.      end
  77.      end
  78.     end
  79.   #--------------------------------------------------------------------------
  80.   # ● 新建帐户
  81.   #--------------------------------------------------------------------------
  82.     def create_a_new_account
  83.       @user_name = $game_system.user_name
  84.       @pass_word = $game_system.pass_word
  85.       filename= make_password_file_name(@user_name)
  86.       i= FileTest.exist?(filename)
  87.       p i
  88.       unless i==false
  89.       @window_information=Window_Reminder.new(4)
  90.       # 弹出框子
  91.       for i in 0..150
  92.       Graphics.update
  93.       end
  94.       @window_information.dispose
  95.       $scene=Scene_UnderTitle.new
  96.       else
  97.       file =File.open(filename,"wb")
  98.       write_password_file(file)
  99.       file.close
  100.       $scene=Scene_UnderTitle.new
  101.       end
  102.     end
  103.   #--------------------------------------------------------------------------
  104.   # ● 生成密码文件文件名
  105.   #--------------------------------------------------------------------------
  106.     def make_password_file_name(i)
  107.       return "User_Information/User_#{i}_Information.psd"
  108.     end
  109.   #--------------------------------------------------------------------------
  110.   # ● 密码文件作成
  111.   #--------------------------------------------------------------------------
  112.     def write_password_file(file)
  113.       Marshal.dump(@user_name, file)
  114.       Marshal.dump(@pass_word, file)
  115.     end
  116.   #--------------------------------------------------------------------------
  117.   # ● 读取密码文件
  118.   #--------------------------------------------------------------------------
  119.     def read_password_file(file)
  120.       @user_name= Marshal.load(file)
  121.       @pass_word= Marshal.load(file)
  122.     end
  123.   end
  124.   
复制代码
回复

使用道具 举报

1

主题

289

帖子

4万

积分

⑧专业

传说中的Bunny雷神~!

积分
46038
发表于 2007-7-20 20:26:56 | 显示全部楼层
不可能失灵,只要后缀名没错就可以检验,除非你的文件是以中文或者非英文/数字命名的。
自从那个天神出现以后,爷的地位就降低了。 (\\__/) ("H.H)  H ( ~  )~| This is Bunny H God.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2025-6-22 11:15 , Processed in 0.010107 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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