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.

Keep getting a weird scripting error....

So I currently have everything I need to actually use the scripts...

I opened up The "Economic tutorial", worked out fine. Then I tryed customizing it in my game...got an error that says

"NoMethodError Occurred While Running this script.
Undefined Method "Add_Shop" for nil:NilClass"

So then I tryed customizing the scripting so it looked EXACTLY like the one in the tutorial. Still got the error...

"NoMethodError Occurred While Running this script.
Undefined Method "Add_Shop" for nil:NilClass"

Then I copied the event and paste it in my rpg, still got the same error.
I then made a new page on his tutorial and paste it then deleted the orginal page, no error at all.
I then made a new game, paste the event and got the
"NoMethodError Occurred While Running this script.
Undefined Method "Add_Shop" for nil:NilClass" error

can someone please help me? This is the weirdest problem I think I have ever come across while using any rpg maker, never had this type of problem scripting with the orginal or the 2k3 version. So whats up with this error?
 
Yes I can, and thank you for your help. The previous error has been re-placed with a new error.

I think that the last error was a simple mistake that I had made.
When loading scripts, you have to copy and paste from the demo and put it into your script editor. I did that but now I'm getting a new error...

Here is the current Script that I am runing, Im not sure if I have said this or not before but this is also the only script I am currently working with,

Its called "Nick's Economy System"
The script in-game is as follows.

"
r = normal_color
self.contents.draw_text(4, 160, 328-cx-2, 32, @total_price.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end
#------------------------#----------------------------------------------------------------------------
# Economic Shop System - by Nick
# Version 2.134 (Hell yeah)
#----------------------------------------------------------------------------
# You may delete all comments except copyright.
# How to use:
# Step 1:
# -Create a shop using $eco.add_shop("name", "trade_type", "description")
# -"name", the store name, to identify shops, cant make 2 shops with same name
# -"trade_type", Standard it is both so you dont have to enter it, use "buy"
# -Or "sell" for buy/sell only shops.
# Step 2:
# -Add items using $eco.add_item(shop, item, type, amount, time_per_unit)
# -Shop can be either shop name or id.
# -Item is just the item id in the database.
# -Type is item(0), weapon(1) or armor(2)
# -Amount is the amount of items automatic in stock and it will restock to.
# -Time_per_unit is the time for 1 item to restock.
# Step 3:
# -Use call script; $scene = Eco_Scene_Shop.new(shopname/id)
# Note:
# -You can also use step 1 and 2 in Game_Economy, def initialize if you prefer.
# -Just replace $eco.shops with just @shops.
# Extra's:
# -If you are going to add items, it might be handier to use ID instead of name
# -For quick acces to ID use @id = $eco.retrieve_id(shopname) to put it in a string
# -Use module ES to adjust quick settings.
# -If you dont like the way i used to set prices, adjust def price in Data_Shopitems
# -And def calprice in Eco_Window_ShopNumber
#----------------------------------------------------------------------------
# Made by: Nick alias "PieNick, "Paashaas", "Generaal Gek", "Ali Anthrax"
# Thanks to: Near_Fantastica for the idea and his great scripts
#----------------------------------------------------------------------------
module ES
RESTOCK = true # Restock items?
CT = true # In the shop menu, let the user choose item type?
SHOPNAME = true # Show shopname in help window when empty?
end

class Data_ShopItems
# All data for items are stored here, and the price calculating
attr_accessor :item
attr_accessor :type
attr_accessor :stock
attr_accessor :default
attr_accessor :time_per_unit
attr_accessor :time_start
#--------------------------------------------------------------------------
def initialize(item, type, default, time_per_unit)
@item = item
@type = type
@stock = default
@default = default
@time_per_unit = time_per_unit
@time_start = Graphics.frame_count
end
#--------------------------------------------------------------------------
def price(sell = false)
case type
when 0
base = $data_items
when 1
base = $data_weapons
when 2
base = $data_armors
end
@baseprice = base[@item].price.to_f
if @default != 0
range = @default.to_f / @stock.to_f
else
if sell
range = 1.30
for i in 0...@stock
range -= 0.05 if range >= 0.80
end
else
range = 2.16
for i in 0...@stock
range -= 0.16 if range >= 0.70
end
end
end
range = 1.25 if range.nan?
if sell
@base = @baseprice / 2
if range == 1
@newprice = @base
elsif range > 1
@newprice = @base * (range * range)
else
@newprice = @base * range
end
@newprice = @baseprice * 3 if @newprice > @baseprice * 3
@newprice = @baseprice / 3 if @newprice < @baseprice / 3
else
@newprice = @baseprice * range
@newprice = @baseprice * 2 if @newprice > @baseprice * 2
@newprice = @baseprice / 2 if @newprice < @baseprice / 2
end
@newprice = @newprice.round
return @newprice
end
end

class Data_Shop
# All data for shops is here
attr_accessor :name
attr_accessor :items
attr_accessor :trade_type
#--------------------------------------------------------------------------
def initialize(name, trade_type)
@name = name
@trade_type = trade_type
@items = []
end
end

class Game_Economy
# Also known as $eco
attr_accessor :shops
#--------------------------------------------------------------------------
def initialize
@shops = []
# After this, you can also create shops and put items in them
end
#--------------------------------------------------------------------------
# Checks every shop and every item if it needs restocking, i think it could
# Cause lag if it needs to search alot of things...
def restock
for shop in 0...@shops.size
for item in 0...@shops[shop].items.size
itemdata = @shops[shop].items[item]
times = (Graphics.frame_count.to_f - itemdata.time_start.to_f) / itemdata.time_per_unit.to_f
if times >= 1.00 and itemdata.time_per_unit != 0
itemdata.time_start = Graphics.frame_count
if itemdata.stock > itemdata.default
itemdata.stock -= times.floor
elsif itemdata.stock < itemdata.default
itemdata.stock += times.floor
end
end
end
end
end
#--------------------------------------------------------------------------
# Add shops using this
def add_shop(name, trade_type = "both")
@shops.push(Data_Shop.new(name, trade_type)) unless $eco.shops.index(name)
end
#--------------------------------------------------------------------------
# Add items to shops using this
def add_item(shop, item, type, default, time_per_unit)
if shop.is_a?(Fixnum)
@id = shop
@name = @shops[@id].name
else
@name = shop
@id = retrieve_id(shop)
end
tpu = time_per_unit * Graphics.frame_rate
@shops[@id].items.push(Data_ShopItems.new(item, type, default, tpu))
end
#--------------------------------------------------------------------------
# Quick ID
def retrieve_id(shop)
for i in 0...@shops.size
if @shops.name == shop
return i
end
end
end
#--------------------------------------------------------------------------
# Created to let you use $eco.price to check price
def price(shop, item, group, sell = false)
if shop.is_a?(Fixnum)
@id = shop
@name = @shops[@id].name
else
@name = shop
@id = retrieve_id(shop)
end
for i in 0...@shops[@id].items.size
@i = i
if @shops[@id].items.item == item and @shops[@id].items.type == group
item_id = i
break
end
end
if item_id
return @shops[@id].items[item_id].price(sell)
else
case group
when 0
item = $data_items[item]
when 1
item = $data_weapons[item]
when 2
item = $data_armors[item]
end
return item.price * 3
end
end
end
# Addition to scene_title to set $eco
class Scene_Title
alias eco_scene_title_cng command_new_game
def command_new_game
eco_scene_title_cng
$eco = Game_Economy.new
end
end
# Addition to scene_map to restock items
class Scene_Map
alias eco_scene_map_update update
def update
if ES::RESTOCK
$eco.restock
end
eco_scene_map_update
end
end
# Addition to scene_load and scene_save to store data
class Scene_Load < Scene_File
alias eco_scene_load_rsd read_save_data
def read_save_data(file)
eco_scene_load_rsd(file)
$eco = Marshal.load(file)
end
end

class Scene_Save < Scene_File
alias eco_scene_save_wsd write_save_data
def write_save_data(file)
eco_scene_save_wsd(file)
Marshal.dump($eco, file)
end
end

# Scene classes.. They're called Eco_*original name* so you can still use
# The default shop without my nifty system :)
class Window_ShopCommand
def draw_item(index, color = normal_color)
self.contents.font.color = color
rect = Rect.new(4 + index * 160, 0, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
#--------------------------------------------------------------------------
def disable_item(index)
self.contents.clear
for i in 0...@item_max
if i == index
draw_item(i, disabled_color)
else
draw_item(i)
end
end
end
end

class Eco_Scene_Shop
def initialize(shop)
if shop.is_a?(Fixnum)
@id = shop
@name = $eco.shops[@id].name
else
@name = shop
for i in 0...$eco.shops.size
if $eco.shops.name == @name
@id = i
break
end
end
end
if @name != $eco.shops[@id].name
print "Error finding shop: " + shop
end
main
end
#--------------------------------------------------------------------------
def main
@help_window = Window_Help.new
if ES::SHOPNAME
@help_window.set_text($eco.shops[@id].name)
else
@help_window.set_text("")
end
@command_window = Window_ShopCommand.new
if $eco.shops[@id].trade_type == "sell"
@command_window.disable_item(0)
elsif $eco.shops[@id].trade_type == "buy"
@command_window.disable_item(1)
end
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 64
@dummy_window = Window_Base.new(0, 128, 640, 352)
@buy_window = Eco_Window_ShopBuy.new(@id)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
@sell_window = Eco_Window_ShopSell.new
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
@number_window = Eco_Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
@status_window = Window_ShopStatus.new
@status_window.visible = false
@select_window = Window_Command.new(160, ["All", "Items", "Weapons", "Armor"])
@select_window.x = 240
@select_window.y = 180
@select_window.active = false
@select_window.visible = false
itemstock = false
weaponstock = false
armorstock = false
for i in $eco.shops[@id].items
itemstock = true if i.type == 0
weaponstock = true if i.type == 1
armorstock = true if i.type == 2
end
@select_window.disable_item(1) if !itemstock and !weaponstock and !armorstock
@select_window.disable_item(1) if !itemstock
@select_window.disable_item(2) if !weaponstock
@select_window.disable_item(3) if !armorstock
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@sell_window.dispose
@number_window.dispose
@status_window.dispose
@select_window.dispose
end
#--------------------------------------------------------------------------
def update
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@sell_window.update
@number_window.update
@status_window.update
@select_window.update
if @command_window.active
update_command
return
end
if @sell_window.active == true or @buy_window.active == true
itemstock = false
weaponstock = false
armorstock = false
for i in $eco.shops[@id].items
itemstock = true if i.type == 0
weaponstock = true if i.type == 1
armorstock = true if i.type == 2
end
normal_color = Color.new(255, 255, 255, 255)
if !itemstock and !weaponstock and !armorstock
@select_window.disable_item(0)
else
@select_window.draw_item(0, normal_color)
end
if !itemstock
@select_window.disable_item(1)
else
@select_window.draw_item(1, normal_color)
end
if !weaponstock
@select_window.disable_item(2)
else
@select_window.draw_item(2, normal_color)
end
if !armorstock
@select_window.disable_item(3)
else
@select_window.draw_item(3, normal_color)
end
end
if @buy_window.active
@sell_window.refresh
update_buy
return
end
if @sell_window.active
@buy_window.refresh
update_sell
return
end
if @number_window.active
update_number
return
end
if @select_window.active
update_select
return
end
end
#--------------------------------------------------------------------------
def update_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0
if $eco.shops[@id].trade_type != "sell"
$game_system.se_play($data_system.decision_se)
@command_window.active = false
if ES::CT
@select_window.visible = true
@select_window.active = true
else
$game_system.se_play($data_system.decision_se)
@buy_window.category = 3
@buy_window.reset
@buy_window.refresh
@buy_window.help_window = @help_window
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@status_window.visible = true
end
else
$game_system.se_play($data_system.buzzer_se)
end
when 1
if $eco.shops[@id].trade_type != "buy"
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
else
$game_system.se_play($data_system.buzzer_se)
end
when 2
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
end
return
end
end
#--------------------------------------------------------------------------
def update_buy
@status_window.item = @buy_window.item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
if ES::SHOPNAME
@help_window.set_text($eco.shops[@id].name)
else
@help_window.set_text("")
end
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
group = 0
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
group = 1
when RPG::Armor
number = $game_party.armor_number(@item.id)
group = 2
end
for i in $eco.shops[@id].items
@item_data = i if i.item == @item.id and i.type == group
end
eco_max = @item_data.stock
if @item == nil or $eco.price(@id, @item.id, @item_data.type) > $game_party.gold or 0 >= eco_max
$game_system.se_play($data_system.buzzer_se)
return
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@id, @item, @item_data.type)
@number_window.active = true
@number_window.visible = true
end
end
#--------------------------------------------------------------------------
def update_sell
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
if ES::SHOPNAME
@help_window.set_text($eco.shops[@id].name)
else
@help_window.set_text("")
end
@command_window.active = true
@dummy_window.visible = true
@buy_window.reset
@buy_window.refresh
@buy_window.help_window = @help_window
return
end
if Input.trigger?(Input::C)
@item = @sell_window.item
@status_window.item = @item
case @item
when RPG::Item
group = 0
when RPG::Weapon
group = 1
when RPG::Armor
group = 2
end
if @item == nil or $eco.price(@id, @item.id, group, true) == 0
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@id, @item, group, sell = true)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
@buy_window.reset
@buy_window.refresh
@buy_window.help_window = @help_window
end
end
#--------------------------------------------------------------------------
def update_number
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
@buy_window.active = true
@buy_window.visible = true
when 1
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.shop_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
case @item
when RPG::Item
$game_party.gain_item(@item.id, @number_window.number)
group = 0
when RPG::Weapon
$game_party.gain_weapon(@item.id, @number_window.number)
group = 1
when RPG::Armor
$game_party.gain_armor(@item.id, @number_window.number)
group = 2
end
for i in 0...$eco.shops[@id].items.size
@item_id = i if $eco.shops[@id].items.item == @item.id and $eco.shops[@id].items.type == group
end
for i in 1..@number_window.number
$eco.shops[@id].items[@item_id].stock -= 1
end
if $eco.shops[@id].items[@item_id].stock == 0 and $eco.shops[@id].items[@item_id].default == 0
$eco.shops[@id].items.delete_at(@item_id)
$eco.shops[@id].items.compact
end
$game_party.lose_gold(@number_window.total_price)
@gold_window.refresh
@buy_window.reset
@buy_window.refresh
@buy_window.help_window = @help_window
@status_window.refresh
@buy_window.active = true
@buy_window.visible = true
when 1
case @item
when RPG::Item
$game_party.lose_item(@item.id, @number_window.number)
group = 0
when RPG::Weapon
$game_party.lose_weapon(@item.id, @number_window.number)
group = 1
when RPG::Armor
$game_party.lose_armor(@item.id, @number_window.number)
group = 2
end
for i in 0...$eco.shops[@id].items.size
@item_id = i if $eco.shops[@id].items.item == @item.id and $eco.shops[@id].items.type == group
end
for i in 0...@number_window.number
if !@item_id
$eco.add_item(@id, @item.id, group, 0, 0)
for i in 0...$eco.shops[@id].items.size
@item_id = i if $eco.shops[@id].items.item == @item.id and $eco.shops[@id].items.type == group
end
end
$eco.shops[@id].items[@item_id].stock += 1
end
$game_party.gain_gold(@number_window.total_price)
@gold_window.refresh
@sell_window.refresh
@status_window.refresh"

And now I'm even getting an error on the demo version (keep in mind that with the previous problem I had, before copying and putting the script in the rpg that I'm trying to start the demo worked fine.

The error is started as follows
"Script "Game_Economy" line 275: TypeError Occured.
No implicit conversion from nil to integer"

I figured that it could be a problem with line 275 in the script, so I compared that on the demo with what was posted by the maker of this scrip linked from the download page.

It turns out that both say "if @name != $eco.shops[@id].name".
 

A J

Member

there are part of the script that are missing

it seem to be a window but it start with no class ???
Code:
r = normal_color
self.contents.draw_text(4, 160, 328-cx-2, 32, @total_price.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end

also it end with no end code

Edit: there are windows that are missing
Eco_Window_ShopBuy.new
Eco_Window_ShopSell.new
Eco_Window_ShopNumber.new
Window_ShopStatus.new
 
A J;226638 said:
there are part of the script that are missing

it seem to be a window but it start with no class ???
Code:
r = normal_color
self.contents.draw_text(4, 160, 328-cx-2, 32, @total_price.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end

also it end with no end code

Edit: there are windows that are missing
Eco_Window_ShopBuy.new
Eco_Window_ShopSell.new
Eco_Window_ShopNumber.new
Window_ShopStatus.new

So where do I stick that code at?
 

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