Basic knowledge to object inspections

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
This post talks about some basics of inspecting objects. You're assumed to have at least little scripting proficiency(beginning Ruby coder having written at least few basic Ruby codes).

The Fundamentals

You probably know inspect under Object. obj.inspect returns a string showing the contents of obj in human readable forms. So it's usually combined with commands printing that string. For example:

print(obj.inspect) # prints obj.inspect on the consolep(obj1, obj2, obj3, ..., objn) # The same as print(obj1.inspect, "\n", obj2.inspect, "\n", obj3.inspect, "\n", ..., "\n", objn.inspect)msgbox_p(obj, obj2, obj3, ..., objn) # creates a message box showing each obji.inspect in a new lineInspecting an object can be really simple, like:

p("1", "2")Will show:

"1""2"On the console.

If the object to be inspected is an Array/Hash:

p(["A", "B"])p({:a => 1, :b => 2})Will show:

["A", "B"]{:a=>1, :b=>2}On the console.

The array ["A", "B"] contains "A" and "B", and the latters are directly linked to the former; Similarly, The hash {:a=>1, :b=>2} contains the key-value pairs :a, 1 and :b, 2, and the latters are directly linked to the former.

If the object to be inspected belongs to a custom class, like:

p(@item) # An instance of Game_BaseItemSomething like this might show:

#<Game_BaseItem:0x897ae70 @class=RPG::Skill, @item_id=91>Game_BaseItem shows the inspected object belongs to Game_BaseItem, 0x897ae70 shows the memory address of that instance, while @class and @item_id are all instance variables belonging to the inspected @item instance variable. @item contains @class and @item_id, and the latters are directly linked to the former.
Inspecting Complicated/Large Objects

Some objects are so small that the result of inspecting them can be completely shown using msgbox_p(); Some are larger that msgbox_p() won't be enough but p() will; Some are so large that using File.open will be needed:

File.open("Filename.extension", "w") { |file| file.print(obj.inspect) } # using "a" instead of "w" also works"Filename.extension" is the name with the extension of the file being opened(or created if it doesn't exist) and "w" opens that file in write mode deleting all previous contents of that file if there's any("a" also opens that file in write mode but will just append new contents to the end of that file instead). file.p(obj) will print obj.inspect to that file.

Inspecting some relatively complicated objects, like this:

p(@shadow_point)Can result in something like this:

#<TSBS::Screen_Point:0x9aa15c8 @x=501, @y=128, @move_obj=#<THEO::Movement::Move_Object:0x9aa1500 @obj=#<TSBS::Screen_Point:0x9aa15c8 ...>, @to_x=-1, @to_y=-1, @real_x=0.0, @real_y=0.0, @x_speed=0.0, @y_speed=0.0, @jump=0.0, @jump_interval=0.0, @offset=0, @duration=0>, @smooth_dur=0, @accel_x=0.0, @accel_y=0.0, @vel_x=0.0, @vel_y=0.0, @sreal_x=150, @sreal_y=156, @starget_x=0.0, @starget_y=0.0, @srev=false, @smove=false>Note that @obj is displayed this way:

#<TSBS::Screen_Point:0x9aa15c8 ...>Upon further inspection, you might realize both @shadow_point and @obj refer to the exact same object, as both have the same memory address 0x9aa15c8. This means displaying the contents of @obj would be displaying that of @shadow_point, which contains @obj, implying doing so would displaying the same contents repeatedly and, in fact, infinitely.

@shadow_point contains @x, @y, @move_obj, @smooth_dur, @accel_x, @accel_y, @vel_x, @vel_y, @sreal_x, @sreal_y, @starget_x, @starget_y, @srev, @smove, and the latters are directly linked to the former.

@move_obj contains @obj, @to_x, @to_y, @real_x, @real_y, @x_speed, @y_speed, @jump, @jump_interval, @offset, @duration, and the latters are directly linked to the former, which is directly linked to @shadow point, meaning what's directly linked to @move_obj is indirectly linked to @shadow_point(@obj can be regarded as an exception as both @obj and @shadow_point refer to the exact same object).

Sometimes, for example, it might not be so clear how @obj is indirectly linked to @shadow_point(even though they refer to the exact same object). In such cases, you may want to reduce the inspection results to clearly show that indirect link. For example, that of @shadow_point can be reduced to this:

#<TSBS::Screen_Point:0x9aa15c8 @move_obj=#<THEO::Movement::Move_Object:0x9aa1500 @obj=#<TSBS::Screen_Point:0x9aa15c8 ...>, @to_x=-1, @to_y=-1, @real_x=0.0, @real_y=0.0, @x_speed=0.0, @y_speed=0.0, @jump=0.0, @jump_interval=0.0, @offset=0, @duration=0>>Which can be further reduced to this:

#<TSBS::Screen_Point:0x9aa15c8 @move_obj=#<THEO::Movement::Move_Object:0x9aa1500 @obj=#<TSBS::Screen_Point:0x9aa15c8 ...>>>Now the indirect link between @obj and @shadow_point is crystal clear and obvious: @obj is directly linked to @move_obj, which is directly linked to @shadow_point.
Inspection Result Reduction Exercises

1. Given the following inspection result of @actions:

[#<Game_Action:0x897ae84 @subject=#<Game_Actor:0x9aa16b8 ...>, @forcing=false, @item=#<Game_BaseItem:0x897ae70 @class=RPG::Skill, @item_id=91>, @target_index=0, @value=0, @last_ecatb_confirm=true, @ecatb_confirm=true>]Reduce it to show how @class, which refers to RPG::Skill, is indrectly linked to @actions.

Answer:

[#<Game_Action:0x897ae84 @item=#<Game_BaseItem:0x897ae70 @class=RPG::Skill>>]
2. Given the following inspection result of @mtrs_skill_guards:

[#<RPG::State:0x579f450 @message2="", @name="EnemyCasting...", @priority=50, @icon_index=0, @message1="", @message4="", @restriction=0, @message3="", @note="\\sequence : EK-Cast\r\n<popup hide rem>\r\n<popup hide add>\r\n<csca enc exclude>", @id=17, @features=[], @auto_removal_timing=2, @min_turns=9999, @max_turns=9999, @chance_by_damage=100, @steps_to_remove=100, @remove_by_walking=false, @remove_at_battle_end=false, @remove_by_damage=false, @remove_by_restriction=false, @description="", @cooldown_rate=1.0, @warmup_rate=1.0, @barrier=nil, @popup_rules={:add_state=>nil, :rem_state=>nil, :dur_state=>nil}, @anim_guard=0, @skill_guard=0, @sg_range=0, @max_opac=255, @sequence="EK-Cast", @state_anim=0, @trans_name="", @color=nil, @attack_id=0, @guard_id=0, @tp_cost_rate=1.0, @hp_cost_rate=1.0, @gold_cost_rate=1.0, @convert_dmg={:hp_physical=>0.0, :hp_magical=>0.0, :mp_physical=>0.0, :mp_magical=>0.0}, @anticonvert=[], @atk_ele=[0, 0, 0, 0, 0, 0, 0, 0, 0], @def_ele=[0, 0, 0, 0, 0, 0, 0, 0, 0], @max_atk_ele=[0, 0, 0, 0, 0, 0, 0, 0, 0], @max_def_ele=[0, 0, 0, 0, 0, 0, 0, 0, 0], @state_triggers=[], @notelines=["\\sequence : EK-Cast", "<popup hide rem>", "<popup hide add>", "<csca enc exclude>"], @ecatb_notes={:charge=>[], :color=>[], :cooldown=>[], :order_icon=>[], :order_opacity=>[], :order_scale=>[], :order_z=>[], :rate=>[], :se=>[], :speed=>[], :start_0=>[], :start_1=>[], :start_2=>[]}, @enemy_ecatb_bar_show=[false, true, false, false], @feature_checked=true, @param_bonuses=[]>]Reduce it to show how all FalseClass are linked(directly or indirectly) to @mtrs_skill_guards.

Answer:

[#<RPG::State:0x579f450 @remove_by_walking=false, @remove_at_battle_end=false, @remove_by_damage=false, @remove_by_restriction=false, @barrier=nil, @popup_rules={:add_state=>nil, :rem_state=>nil, :dur_state=>nil}, @color=nil, @enemy_ecatb_bar_show=[false, false, false]>]
3. (Advanced level real example)Given the following inspection result of actor(up to 120 KB):

200 Scripts 30 Scripters Inspect Example 2

Reduce it to show how all Proc are linked(directly or indirectly) to actor.

Answer(I used nearly 4 hours to come up with this having only 3 KB):

200 Scripts 30 Scripters Reduced Inspect Example 2


That's all for now. I hope this can help you grasp these basic knowledge. For those comprehending object inspections, feel free to correct me if there's anything wrong :D

For those wanting to have a solid understanding to object inspections, I might open a more advanced topic for that later :)
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top