Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Script not working?

Hi. I have a custom 'name input' script.

This is the code:

Code:
#==============================================================================

# â–  Scene_Name

#------------------------------------------------------------------------------

# Allows for Name Input via the Keyboard

#==============================================================================

 

class Scene_Name

 

  #--------------------------------------------------------------------------

  # ● メイン処理

  #--------------------------------------------------------------------------

  def main

    @spriteset = Spriteset_Map.new

    @name = Window_Name.new

    @name.z = 999999

    @input = Window_NameInput.new

    @input.z = 999999

    # トランジション実行

    Graphics.transition

    # メインループ

    loop do

      # ゲーム画面を更新

      Graphics.update

      # フレーム更新

      update

      # 画面が切り替わったらループを中断

      if $scene != self

        break

      end

    end

    # トランジション準備

    Graphics.freeze

    # メッセージウィンドウを解放

    @spriteset.dispose

    @name.dispose

    @input.dispose

    # タイトル画面に切り替え中の場合

  end

  

  #--------------------------------------------------------------------------

  # ● フレーム更新

  #--------------------------------------------------------------------------

  def update

    @spriteset.update

    @name.update

    @input.update

  end

end

 

#==============================================================================

# â–  Window_Chat

#------------------------------------------------------------------------------

#  Displays chat messages.

#==============================================================================

 

class Window_Name < Window_Base

  #--------------------------------------------------------------------------

  # ● Initializes chat window.

  #--------------------------------------------------------------------------  

  def initialize

    super(40, 140, 400, 134)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.name = $fontface

    self.contents.font.size = $fontsize

    self.contents.font.color = normal_color

    self.opacity = 255

    refresh

  end

  

  #--------------------------------------------------------------------------

  # ● Refreshes chat window.

  #--------------------------------------------------------------------------  

  def refresh

    self.contents.clear

    x = 4

    y = 0

    w = 480

    h = 32

    self.contents.draw_text(x,y,w,h, "Type your name by using the keyboard.")

    self.contents.draw_text(x,y+24,w,h, "Press Shift-key to use capital letters.")

    self.contents.draw_text(x,y+48,w,h, "Press Backspace-key to remove a letter")

    self.contents.draw_text(x,y+72,w,h, "and press Enter when you're done.")

    

  end

  #--------------------------------------------------------------------------

  # ● Updates chat window.

  #--------------------------------------------------------------------------  

  def update

    refresh

    super

  end

end

 

#==============================================================================

#  Window_ChatInput

#------------------------------------------------------------------------------

# 

#==============================================================================

 

class Window_NameInput < Window_Base

  

  #--------------------------------------------------------------------------

  # ● Initializes chat input window.

  #--------------------------------------------------------------------------  

  def initialize

    super(40, 60, 400, 80)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.name = $fontface

    self.contents.font.size = $fontsize

    self.contents.font.color = normal_color

    self.opacity = 255

    @text = []

    refresh

  end

  

  #--------------------------------------------------------------------------

  # ● Refreshes chat input window.

  #--------------------------------------------------------------------------  

  def refresh

    @log = @text.to_s

    self.contents.clear

    actor = $game_party.actors[0]

    draw_actor_graphic(actor, 32, 48)

    self.contents.draw_text(64, 4, 480, 48, @text.to_s + "_")

  end

  

  #--------------------------------------------------------------------------

  # ● Refreshes chat input window.

  #--------------------------------------------------------------------------  

  def add(char)

    if @text.size >= $game_temp.name_max_char

      $game_system.se_play($data_system.buzzer_se)

    else

      @text.push(char.to_s)

      refresh

    end

  end

  #--------------------------------------------------------------------------

  # ● Updates input chat window.

  #--------------------------------------------------------------------------  

  def update

    # Sends chat message.

    if Input.getkey(13)

      if @text.size == 0

        $game_system.se_play($data_system.buzzer_se)

      else

        $pkmn.trainername = @text.to_s

        $game_variables[1] = @text.to_s

        $game_variables[2] = $game_party.actors[0].name

        $scene = Scene_Map.new

      end

    end

    # Removes last entry in test.

    if Input.getkey(8)

      if @text.size == 0

        $game_system.se_play($data_system.buzzer_se)

      else

        @text.delete_at(-1)

        refresh

      end

    end

    # Adds a pressed key.

    if Input.getstate(16)

      add("A") if Input.getkey(65)

      add("B") if Input.getkey(66)

      add("C") if Input.getkey(67)

      add("D") if Input.getkey(68)

      add("E") if Input.getkey(69) 

      add("F") if Input.getkey(70)

      add("G") if Input.getkey(71)

      add("H") if Input.getkey(72)

      add("I") if Input.getkey(73)

      add("J") if Input.getkey(74)

      add("K") if Input.getkey(75)

      add("L") if Input.getkey(76)

      add("M") if Input.getkey(77)

      add("N") if Input.getkey(78)

      add("O") if Input.getkey(79)

      add("P") if Input.getkey(80)

      add("Q") if Input.getkey(81)

      add("R") if Input.getkey(82)

      add("S") if Input.getkey(83)

      add("T") if Input.getkey(84)

      add("U") if Input.getkey(85)

      add("V") if Input.getkey(86)

      add("W") if Input.getkey(87)

      add("X") if Input.getkey(88)

      add("Y") if Input.getkey(89)

      add("Z") if Input.getkey(90)

      add(")") if Input.getkey(48)

      add("!") if Input.getkey(49)

      add("@") if Input.getkey(50)

      add("#") if Input.getkey(51)

      add("$") if Input.getkey(52)

      add("%") if Input.getkey(53)

      add("^") if Input.getkey(54)

      add("&") if Input.getkey(55)

      add("*") if Input.getkey(56)

      add("(") if Input.getkey(57)

      add(":") if Input.getkey(186)

      add("+") if Input.getkey(187)

      add("<") if Input.getkey(188)

      add("_") if Input.getkey(189)

      add(">") if Input.getkey(190)

      add("?") if Input.getkey(191)

      add("{") if Input.getkey(219)

      add("|") if Input.getkey(220)

      add("}") if Input.getkey(221)

      add("\"") if Input.getkey(222)

    else

      add("a") if Input.getkey(65)

      add("b") if Input.getkey(66)

      add("c") if Input.getkey(67)

      add("d") if Input.getkey(68)

      add("e") if Input.getkey(69) 

      add("f") if Input.getkey(70)

      add("g") if Input.getkey(71)

      add("h") if Input.getkey(72)

      add("i") if Input.getkey(73)

      add("j") if Input.getkey(74)

      add("k") if Input.getkey(75)

      add("l") if Input.getkey(76)

      add("m") if Input.getkey(77)

      add("n") if Input.getkey(78)

      add("o") if Input.getkey(79)

      add("p") if Input.getkey(80)

      add("q") if Input.getkey(81)

      add("r") if Input.getkey(82)

      add("s") if Input.getkey(83)

      add("t") if Input.getkey(84)

      add("u") if Input.getkey(85)

      add("v") if Input.getkey(86)

      add("w") if Input.getkey(87)

      add("x") if Input.getkey(88)

      add("y") if Input.getkey(89)

      add("z") if Input.getkey(90)

      add("0") if Input.getkey(48)

      add("1") if Input.getkey(49)

      add("2") if Input.getkey(50)

      add("3") if Input.getkey(51)

      add("4") if Input.getkey(52)

      add("5") if Input.getkey(53)

      add("6") if Input.getkey(54)

      add("7") if Input.getkey(55)

      add("8") if Input.getkey(56)

      add("9") if Input.getkey(57)

      add(";") if Input.getkey(186)

      add("=") if Input.getkey(187)

      add(",") if Input.getkey(188)

      add("-") if Input.getkey(189)

      add(".") if Input.getkey(190)

      add("/") if Input.getkey(191)

      add("[") if Input.getkey(219)

      add("\\") if Input.getkey(220)

      add("]") if Input.getkey(221)

      add("'") if Input.getkey(222)

    end

    add(" ") if Input.getkey(32)

    add("*") if Input.getkey(106)

    add("+") if Input.getkey(107)

    add("-") if Input.getkey(109)

    add("/") if Input.getkey(111)

  end

  

end

It works fine on the pokemon started kit on which I found it. Yet when I put it into my game I get the following error:

Script 'Name Input' line 143: NoMethodError occured.

undefined method 'getkey' for Input:Module

Any ideas?

Thanks
 
You'll need to copy the Input module from the Pokemon SDK.
That module has this specific method, getkey, that isn't found at the standard RGSS Input module. It's probably for using the whole keyboard.
Well, have a look at the Pokémon SDK scripts and try searching for this Input module. Copy it to your project and it'll (probably) work.

SEE YA!!!!!
 
Ok. So I copied the input module over to my game. However, again an error occurred. I went into the script and found this line was causing problems:

Code:
$pkmn.trainername = @text.to_s

As my game is not pokemon, I naturally deleted the line. Guess what? The name input window worked, but didn't change the name of the actor. I'm guessing this line is important then. What i can I change it to, so that it will affect the actor and not the 'pokemon trainer' !?
 
Try changing it to (This is purely based off speculation, as thats all I can do unless you provide the Imput script aswell);
Code:
$actor.name = @text.to_s
However this will mean you have to paste this into def main,
Code:
@actor = actor

@name = actor.name
. Try it, if it doesn't work post the Imput script and I'll give it another go.
 
Hi. Thanks for replying - I;m a bit of a script noob, whereabouts do I put that line in Main? Under the rest of the script? My Main looks like this:

Code:
#==============================================================================

# ** Main

#------------------------------------------------------------------------------

#  After defining each class, actual processing begins here.

#==============================================================================

 

begin

   # Prepare for transition

    $defaultfonttype = $fontface = $defaultfontface = $fonttype = "Arial"

    $defaultfontsize = $fontsize = (20) 

      Graphics.freeze

    # Make scene object (title screen)

  $scene = Scene_Intro.new

    # Call main method as long as $scene is effective

  while $scene != nil

    $scene.main

  end

  # Fade out

  Graphics.transition(20)

rescue Errno::ENOENT

  # Supplement Errno::ENOENT exception

  # If unable to open file, display message and end

  filename = $!.message.sub("No such file or directory - ", "")

  print("Unable to find file #{filename}.")

end

 
 
Ahh sorry you've misunderstood me, you paste it into the def main of that script so it should be like
Code:
  def main

    @spriteset = Spriteset_Map.new

    @actor = actor

    @name2 = actor.name

    @name = Window_Name.new

    @name.z = 999999

    @input = Window_NameInput.new

    @input.z = 999999

    # トランジション実行

    Graphics.transition

    # メインループ

    loop do

      # ゲーム画面を更新

      Graphics.update

      # フレーム更新

      update

      # 画面が切り替わったらループを中断

      if $scene != self

        break

      end

    end

    # トランジション準備

    Graphics.freeze

    # メッセージウィンドウを解放

    @spriteset.dispose

    @name.dispose

    @name2.dispose

    @actor.dispose

    @input.dispose

    # タイトル画面に切り替え中の場合

  end
Replace the def_main of the first script with that, change the line I told you to in my previous post and try it.
 
I undestood this time :D -

However I got this error:

Code:
Script 'Name Input' line 14: NameError ocurred.

 

undefined local variable or method 'actor' for #<Scene_Name0x724cec8>

 

Any ideas? Or is it time for me to post the input script??
 
Yeah post the imput script please, I'll give it a look.

EDIT: Could of been a simple error on my part, sorry give this a quick try;
Code:
@actor = $game_party.actors[1]
replace the other
Code:
@actor = actor
with that and it may or may not work.
 
New Error this time:

line 15

undefined local variable or method 'actor' for <Scene_Name:0x724a960>


Here is the input script:

Code:
#==============================================================================

# â–  Input                                                Created by: Cybersam

#------------------------------------------------------------------------------

#  Adds full keyboard support to module Input.

#==============================================================================

module Input

  #--------------------------------------------------------------------------

  # - Returns true when a key is pressed.

  #--------------------------------------------------------------------------  

  def Input.getkey(key)

    Win32API.new("user32", "GetAsyncKeyState", "i", "i").call(key) & 0x01 == 1

  end

  #--------------------------------------------------------------------------

  # - Returns a key's state.

  #--------------------------------------------------------------------------  

  def Input.getstate(key)

    return (not Win32API.new("user32", "GetKeyState", "i", "i").call(key).between?(0, 1))

  end

end

 
 
Sorted. I hope. Replace the current Name_Imput script with this one;
It doesn't show an actor graphic, at the moment I'm going to be looking at this to see if I can fix it. But other than that works fine for me with that Imput script.

EDIT: It was a stupid error from me once again, very sorry about this. It'll now draw the correct actor graphic when you call the script. Just paste the code where ever above main and below the imput script.
Code:
#==============================================================================

# â–  Scene_Name

#------------------------------------------------------------------------------

# Allows for Name Input via the Keyboard

#==============================================================================

 

class Scene_Name

 

  #--------------------------------------------------------------------------

  # ● メイン処理

  #--------------------------------------------------------------------------

  def main

    @spriteset = Spriteset_Map.new

    @name = Window_Name.new

    @name.z = 999999

    @input = Window_NameInput.new

    @input.z = 999999

    # トランジション実行

    Graphics.transition

    # メインループ

    loop do

      # ゲーム画面を更新

      Graphics.update

      # フレーム更新

      update

      # 画面が切り替わったらループを中断

      if $scene != self

        break

      end

    end

    # トランジション準備

    Graphics.freeze

    # メッセージウィンドウを解放

    @spriteset.dispose

    @name.dispose

    @input.dispose

    # タイトル画面に切り替え中の場合

  end

 

  #--------------------------------------------------------------------------

  # ● フレーム更新

  #--------------------------------------------------------------------------

  def update

    @spriteset.update

    @name.update

    @input.update

  end

end

 

#==============================================================================

# â–  Window_Chat

#------------------------------------------------------------------------------

#  Displays chat messages.

#==============================================================================

 

class Window_Name < Window_Base

  #--------------------------------------------------------------------------

  # ● Initializes chat window.

  #--------------------------------------------------------------------------  

  def initialize

    super(40, 140, 400, 134)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.color = normal_color

    self.opacity = 255

    refresh

  end

 

  #--------------------------------------------------------------------------

  # ● Refreshes chat window.

  #--------------------------------------------------------------------------  

  def refresh

    self.contents.clear

    x = 4

    y = 0

    w = 480

    h = 32

    self.contents.draw_text(x,y,w,h, "Type your name by using the keyboard.")

    self.contents.draw_text(x,y+24,w,h, "Press Shift-key to use capital letters.")

    self.contents.draw_text(x,y+48,w,h, "Press Backspace-key to remove a letter")

    self.contents.draw_text(x,y+72,w,h, "and press Enter when you're done.")

   

  end

  #--------------------------------------------------------------------------

  # ● Updates chat window.

  #--------------------------------------------------------------------------  

  def update

    refresh

    super

  end

end

 

#==============================================================================

#  Window_ChatInput

#------------------------------------------------------------------------------

#

#==============================================================================

 

class Window_NameInput < Window_Base

 

  #--------------------------------------------------------------------------

  # ● Initializes chat input window.

  #--------------------------------------------------------------------------  

  def initialize

    super(40, 60, 400, 80)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.color = normal_color

    self.opacity = 255

    @text = []

    refresh

  end

 

  #--------------------------------------------------------------------------

  # ● Refreshes chat input window.

  #--------------------------------------------------------------------------  

  def refresh

    @log = @text.to_s

    self.contents.clear

    actor = $game_party.actors[0]

    draw_actor_graphic(actor, 32, 48)

    self.contents.draw_text(64, 4, 480, 48, @text.to_s + "_")

  end

 

  #--------------------------------------------------------------------------

  # ● Refreshes chat input window.

  #--------------------------------------------------------------------------  

  def add(char)

    if @text.size >= $game_temp.name_max_char

      $game_system.se_play($data_system.buzzer_se)

    else

      @text.push(char.to_s)

      refresh

    end

  end

  #--------------------------------------------------------------------------

  # ● Updates input chat window.

  #--------------------------------------------------------------------------  

  def update

    # Sends chat message.

    if Input.getkey(13)

      if @text.size == 0

        $game_system.se_play($data_system.buzzer_se)

      else

        $game_party.actors[0].name = @text.to_s

        $game_variables[1] = @text.to_s

        $game_variables[2] = $game_party.actors[0].name

        $scene = Scene_Map.new

      end

    end

    # Removes last entry in test.

    if Input.getkey(8)

      if @text.size == 0

        $game_system.se_play($data_system.buzzer_se)

      else

        @text.delete_at(-1)

        refresh

      end

    end

    # Adds a pressed key.

    if Input.getstate(16)

      add("A") if Input.getkey(65)

      add("B") if Input.getkey(66)

      add("C") if Input.getkey(67)

      add("D") if Input.getkey(68)

      add("E") if Input.getkey(69)

      add("F") if Input.getkey(70)

      add("G") if Input.getkey(71)

      add("H") if Input.getkey(72)

      add("I") if Input.getkey(73)

      add("J") if Input.getkey(74)

      add("K") if Input.getkey(75)

      add("L") if Input.getkey(76)

      add("M") if Input.getkey(77)

      add("N") if Input.getkey(78)

      add("O") if Input.getkey(79)

      add("P") if Input.getkey(80)

      add("Q") if Input.getkey(81)

      add("R") if Input.getkey(82)

      add("S") if Input.getkey(83)

      add("T") if Input.getkey(84)

      add("U") if Input.getkey(85)

      add("V") if Input.getkey(86)

      add("W") if Input.getkey(87)

      add("X") if Input.getkey(88)

      add("Y") if Input.getkey(89)

      add("Z") if Input.getkey(90)

      add(")") if Input.getkey(48)

      add("!") if Input.getkey(49)

      add("@") if Input.getkey(50)

      add("#") if Input.getkey(51)

      add("$") if Input.getkey(52)

      add("%") if Input.getkey(53)

      add("^") if Input.getkey(54)

      add("&") if Input.getkey(55)

      add("*") if Input.getkey(56)

      add("(") if Input.getkey(57)

      add(":") if Input.getkey(186)

      add("+") if Input.getkey(187)

      add("<") if Input.getkey(188)

      add("_") if Input.getkey(189)

      add(">") if Input.getkey(190)

      add("?") if Input.getkey(191)

      add("{") if Input.getkey(219)

      add("|") if Input.getkey(220)

      add("}") if Input.getkey(221)

      add("\"") if Input.getkey(222)

    else

      add("a") if Input.getkey(65)

      add("b") if Input.getkey(66)

      add("c") if Input.getkey(67)

      add("d") if Input.getkey(68)

      add("e") if Input.getkey(69)

      add("f") if Input.getkey(70)

      add("g") if Input.getkey(71)

      add("h") if Input.getkey(72)

      add("i") if Input.getkey(73)

      add("j") if Input.getkey(74)

      add("k") if Input.getkey(75)

      add("l") if Input.getkey(76)

      add("m") if Input.getkey(77)

      add("n") if Input.getkey(78)

      add("o") if Input.getkey(79)

      add("p") if Input.getkey(80)

      add("q") if Input.getkey(81)

      add("r") if Input.getkey(82)

      add("s") if Input.getkey(83)

      add("t") if Input.getkey(84)

      add("u") if Input.getkey(85)

      add("v") if Input.getkey(86)

      add("w") if Input.getkey(87)

      add("x") if Input.getkey(88)

      add("y") if Input.getkey(89)

      add("z") if Input.getkey(90)

      add("0") if Input.getkey(48)

      add("1") if Input.getkey(49)

      add("2") if Input.getkey(50)

      add("3") if Input.getkey(51)

      add("4") if Input.getkey(52)

      add("5") if Input.getkey(53)

      add("6") if Input.getkey(54)

      add("7") if Input.getkey(55)

      add("8") if Input.getkey(56)

      add("9") if Input.getkey(57)

      add(";") if Input.getkey(186)

      add("=") if Input.getkey(187)

      add(",") if Input.getkey(188)

      add("-") if Input.getkey(189)

      add(".") if Input.getkey(190)

      add("/") if Input.getkey(191)

      add("[") if Input.getkey(219)

      add("\\") if Input.getkey(220)

      add("]") if Input.getkey(221)

      add("'") if Input.getkey(222)

    end

    add(" ") if Input.getkey(32)

    add("*") if Input.getkey(106)

    add("+") if Input.getkey(107)

    add("-") if Input.getkey(109)

    add("/") if Input.getkey(111)

  end

 

end
 
Problem sorted - Thanks!

As a matter of interest - whereabouts in the script would I edit for the coordinates of the window? As at the moment it is in the top left of the screen and I want it in the Middle?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top