The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Chaos17 on August 02, 2014, 09:52:42 AM

Title: [Solved] [VX ACE] Is this corectly coded ?
Post by: Chaos17 on August 02, 2014, 09:52:42 AM
Hello,

Can someone help me check if this script is correctly coded, please ?
A friend tried to teach how to script months ago and this is the result.
But I'm unable at the moment to meet him.

The purpose of this script is to help me call a sprite from a sprite sheet and to change it to my taste through a script command in an event. Yes, I'm more an eventer than a scripter...
Code: [Select]
class Chara < Game_Interpreter
 
 def  initialize(id, type, nom, x=0, y=0, z=0, m)
    sprite = Sprite.new
   
    sprite.x = x
    sprite.y = y
    sprite.z = z
   
    sprite.mirror = m
    m = false
   
    chemin = "Graphics/Units/#{type}/#{nom}"
    sprite.bitmap = Cache.normal_bitmap(chemin)
   
    w = sprite.width/3
    h = sprite.height/5
    sprite.src_rect.set(0, 0, w, h)
   
    V[id] = sprite
  end
 
    def self.frame(id, frame)
     V[id].src_rect.x = frame*V[id].width
   end
   
   def self.pose (id, pose)
     V[id].src_rect.y = pose*V[id].height
   end
   
    def self.add(id, type, nom)
      chemin = "Graphics/Units/#{type}/#{nom}"
      bitmap = Cache.normal_bitmap(chemin)
      rect = Rect.new(0, 0, bitmap.width, bitmap.height)
      V[id].bitmap.blt(0, 0, bitmap, rect)
      end
   end
Title: Re: [VX ACE] Is this corectly coded ?
Post by: D&P3 on August 02, 2014, 01:33:54 PM
It LOOKS fine...
I can think of improvements to the code. But you'll figure those out yourself in time and with experience :)


Brief mention:
Code: [Select]
   w = sprite.width/3
    h = sprite.height/5
    sprite.src_rect.set(0, 0, w, h)
This assumes that the spritesheet (should you ever use any different one) will always contains 3 sprites horizontally and 5 sprites vertically.
If that is ever not the case. Your result will end up looking incredibly weird.


I'm not sure what you want me to critique here, I mean the code looks fine, it looks as though it should do as you have said.
Is that all you wanted to know? Does it not work?


Title: Re: [VX ACE] Is this corectly coded ?
Post by: Chaos17 on August 09, 2014, 09:19:09 AM
Thank you for your reply.
I'm happy to know that the script is correct.