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.

Help with one of my own scripts >_<

Status
Not open for further replies.
Well this is kind of embarassing, but here goes.

http://www.rmxp.org/forums/showthread.php?t=10736
This is my script that allows character sprites a custom amount of frames, defined in the filename of the graphic (so every character can have a different amount of frames if they want).

If you're running an otherwise default game, it works perfect. However, I've just started working on a script that changes the @character_name variable in order to change the character sprite temporarily. However, when I do this and the new sprite has a different number of frames, it looks messed up because it uses the same amount of frames as the last graphic.

It took ages for me to get it running nice and proper in the first place, but now it looks like it needs a rewrite/modifications. I've already tried rewriting it once to get it working, but no dice - I'm really at a loss here now.

Edit: Formal request here.
 
I can understand why are using the @character_name to use a regexp to derive the number of frames, but why not just make a seperate instance to define this? It truthfully might make your work a little easier to modify.

If you aren't into that, could you perhaps set up some demo of exactly what is happening that is causing the error? I am not 100% clear on what you are saying.
 
Seperate instance? See this is the kind of advice/help I need.

Easy way to show what I'm talking about:

Start a project with the script, add a "print @character.character_frames" line in the Sprite_character part, right before it defines the @cw variable.

Duplicate a character graphic, rename them per the instructions for my script, so each filename has a different amount of frames (they don't have to in reality obviously).

Set starting graphic for player in database to one or the other.
Then make an event that calls a script that changes the @character_name variable (for the Game_Character object of the player obviously) to the other graphic.

Start the game, a couple of boxes should pop up with the frames of the player and the frames of your event. Then go talk to the event, and another box should pop up (at least I think it should, if it doesn't just add a print line to the event instead) with the number of frames - however you'll notice it's the same amount as before, and the duplicate character graphic with the different amount of frames in the filename will look exactly the same as the other one.

If you need an idea how it should be working, just place another event with a normal "change actor graphic" command.


If you need more explanation, let me know. I think I'll make a demo tomorrow if you still need it.
 
You know what? I am the biggest idiot in the world.

I went to put together a demo to demonstrate my problem, except when I tried it out everything worked as it should. Turns out the naming of the file in my project was wrong all along. You see I was calling a method that did this:
Code:
@character_name += "-stand"
so for testing purposes I copied the filename of my walk graphic, renamed a 1-frame charset, and added "-stand" to the end. Why I never thought that I might have to change the "f_" part is a mystery, but my mind was probably set on the fact that the file had to be named exactly the same as the other one with "-stand" on the end for the method to work. Needless to say I am extremely embarrassed, and extremely sorry for taking up any of anyone's time.

So my whole project has been on hold for over a month when there was nothing wrong -_-

SephirothSpawn: I only just understood now what you meant about a seperate instance - it's the lack of the word "variable" that put me off :P
I had no use for one in the past, but now it's possible I might. With all that said though, would you have a recommended regular expression and/or way of doing things that you would personally use in place of mine? Regular expressions aren't my strong point :P
 
I would only really recommend making a hash that controls your character_frames and character_adjust_y in Game_Character.

Code:
class Game_Character
  Character_Frames = {}
  Character_Frames['001-Fighter01'] = 8
  Character_Frames.default = 4
  Character_Adjust_Y = {}
  Character_Adjust_Y.default = 0
  def character_frames
    return Character_Frames[@character_name]
  end
  def character_adjust_y
    return Character_Adjust_Y[@character_name]
  end
end

Using that, you don't need to do the gsub every time, and if more than 1 script tries to use the same f_ sub, then an error will occur. This is a personal prefrence though. Your way is more user-friendly, but can cause future incompatablities.

The other thing would to just use an attr_accessor, but I don't think that would be a wise choice here.
 
Hmm, the hash is a good idea, just might be a problem to keep maintaining it - that being said, I could really switch to it at any time if needed.

I did actually go through a whole development stage with the script using an attr_accessor - just wondering why you say it'd be unwise?
 
Not necessarily unwise, but would require quite a few more steps for users. They would have to change the character_name instance, but the character_frames as well. Just too much work compared to the other 2 ways.
 
Status
Not open for further replies.

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