[Solved] [VX ACE] Is this corectly coded ?

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 57
RMRK Junior
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
« Last Edit: August 10, 2014, 01:39:00 AM by yuyu! »

*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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?



**
Rep:
Level 57
RMRK Junior
Thank you for your reply.
I'm happy to know that the script is correct.