Help with defining method for items

Status
Not open for further replies.

SilviaS152002

Villager
Member
Joined
Apr 19, 2019
Messages
7
Reaction score
0
First Language
Chinese
Primarily Uses
RMVXA
I am trying to make a system where each item has its own weight, and when the characters cannot carry all their stuff, they cannot move and have to throw away their stuff.

The main focus for help:
Here is the code in the scripts:
class RPG::Item
def weight
if @weight.nil?
weight_checker
return @weight
else
return @weight
end
end

def weight_checker
@weight = self.note =~ /<Weight: (.*)>/i ? $1 : 0
end
end

Code in common events:
hepl.PNG

The thing is, it breaks on the 1st line after "else" in the common event with a " "weight" not found for nil:nilClass "

how do I define "weight" properly?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
[move]Learning Ruby and RGSDx[/move]
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
281
Reaction score
106
First Language
English
Primarily Uses
RMXP
All the database globals ($data_*) start at index 1, not 0. So init variable 63 to 1.
 

SilviaS152002

Villager
Member
Joined
Apr 19, 2019
Messages
7
Reaction score
0
First Language
Chinese
Primarily Uses
RMVXA
Thanks! (I kinda feel like an idiot but thanks anyways) :)
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,078
Members
137,580
Latest member
Snavi
Top