Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: StorocnekXx on March 21, 2014, 06:10:13 am

Title: Little scripting problems with windows/text/variables/conditions
Post by: StorocnekXx on March 21, 2014, 06:10:13 am
Hello everyone :)
I'm trying to learn the basics of scripting so far with some tutorials suggested. I need to learn a bit of scripting, to create windows showing up hero HP, enemy HP and so on. I do not really want to create battlesystems or menues or stuff like (Actually, I'd love to do so, but not in the near future).
I have made a battle system done with eventy, but I hate 'klicking' on an enemy to ask for it's HP. That sucks. I just want a window over their head to show their HP.
Anways...
I read quite a lot with confusing words, several phrases, new vocabulary and now I wanted to give it a shot on my own.
As I went through this (http://www.rpgrevolution.com/tutorial/the-script-builders%27-tutorials-lesson-1:-basic-windows_265.html) tutorial, I wanted to create my own window.
This is the 'script' I came up with:
Spoiler: ShowHide
class Self_HP < Window_Base
 def initialize
   super(448, 160, 96, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 def refresh
   self.contents.clear
   self.contents.draw_text(0, 0, 100, 100, "Text.")
 end
end

   
To call the 'script' I use the command '$window = Self_HP.new'.
... and it does show up a window at the wanted location, but it does not show the text massage anywhere on the screen. I changed several numbers of the draw_text thingy (is it a method? Object? Whatsoever, I read so much, I'm confusing myself with the phrases anyway) but it still does not show up the next (e.g., I changed it to the same variables as I put in "super()"). The typical "Is you Mainscript correct? Does it have a font defined?" and so on does not seem to be the problem, because I allready took the main script from other working projects.
Edit: Looks like my window is too small to include a text. If I extend the window itself, the text can be seen. However, there is "huge" space between the borders of the Windowd and the actually text. Can this somehow be made smaller? I really just want a small window showing 2 variables (HP), like "100/102" - There's no need for more space than that.
I may repeat myself: I'm totally new, so maybe this is just something plain simple I absolutly do not get.

Next thing is, the window won't close for me. The tutorial states to use '$window.dispose' to dispose the window made in the tutorial, but sadly it does not tell me how to dispose any window just created. (Using '$window.dispose' results in an error.)
Edit: This is important. As I don't know how to actually refresh some variables or something (Like "Has the variable/Hp changed?" -> "change the shown number aswell), I want to erase the allready created window and create a new one with the correct numbers. I don't really get what  $window.dispose does, so it sometimes delets something, sometimes it does not and it just confuses me. So the question is: How do I delete shown windows?
Edit2: Done, thanks Blizz.

But while we are at it, there's another question (somehow) fitting to this problem: How do I show up variables defined in the databes/due to events? Like Hero's HP? I want this window to show up the actuall and the maximum HP of my (only) hero1 in the party in exactly that window (Actuall HP / Max HP). Do I have to first define a @variable and set it (=) to an 'normal' variable? (Yet again, those 'global', 'class' and other variables keep confusing me. Need to read those tutorials again).
Edit: Guess I figgured this out. Nevermind that then.
Edit2: ...It just does not refresh. I solved this with deleteing the old window and create a new one with the new numbers, but there is a problem. (Look above)
Edit3: Done.

Next thing is how to set up conditions (I did NOT read the tutorial for that so far, so maybe it will be clear after I read it. However, I'm asking it now to not open another thread later on or eventually double post).
I have a variable asking how many enemys the battle has. For every enemy excisting, there shall be a window over their head showing up their actuall/max HP, just like for my hero. I thought about something like this in general: (Of course, this is not something implementable)
Spoiler: ShowHide
HowManyEnemys? == 1
    Then create_window (over enemy head)
    draw_text("actuallhp / maxhp")
HowManyEnemys? == 2
    Then Do as above
    create_window2 (over second enemy head)
    draw_text("actuallhpmonster2 / maxhpmonster2")
HowManyEnemys? == 3
    Then do as above
    create_window3 (over third enemy head)
    draw_text("actuallhpmonster3 / maxhpmonster3")
HowManyEnemysAreDefeated? == HowManyEnemys #Every enemy should be dead until windows are removed (bc you can attack corpses (in my system))
    Then allwindows.dispose

First of all: Is this possible? It does not sound complicated (for me), but I'd better ask.
Second: Is it easy to set up or do I need to know a lot more about scripting?

Edit: I solved this somehow else, with a simple conditional branch "How many enemys?" -> 1? -> Call Enemy1_HP // -> 2? Call Enemy1_HP and Enemy2_HP and so on. Does work so far. However, I still got stuck in deleating and newcreating windows. Look above.
Edit2: Done.



Edit: How do I ask for an enemies' name in the database? I want to a window to show up, telling the name of [EnemyNumber10InDatabase]. How do I do that?


So, since that's quite some questions to ask for in the first place, I'd be very thankfull if somewould would help me out. Maybe it's something that easy that I have just overseen, but, as stated, ... I'm new to that kind of stuff.

Thank you very much for reading this!

Greetings,
StorocnekXx