Special Support - A great place to learn to Script

This line...

self.contents = Bitmap.new(width-32, height-32)

...tells the game to draw the contents inside of each window, so there are 16 px on the left and another 16 px on the right hand side, the same happens with the upper and lower side of the window, where you can't see any text or icon, they'd be hidden by the window borders. So you gotta leave it as it is or create a transparent window (opacity = 0) of the same size of the larger window and see if it allows you to place the text message like this...

self.contents.draw_text(0, 0, 50, 0, $nombre_habilidad)

you could also use something like...

self.contents.draw_text(0, 0, 50, -4, $nombre_habilidad)

but no one here would ever recommend to use negative values even if they'd work fine.

BTW, don't declare too many $global_variables, they're the worst you can ever see, even if they allow you to get access to multiple things from anywhere. Use as few as possible, maybe you may create between 1 and 2 of them only. If they are used for very similar purposes, merge them, leave only one of them alive and get rid of the other one.
Kain Nobel wrote:
Hello :)

Wow, I haven't had to ask anything in a long time, but I was recently messing and experimenting with $game_map.passable? method and I've always been curious what this value is exactly and how it works, why its used, etc...

0x0f

When I use 'p' or 'print' to view the value, it says '15' so... I don't understand why that number? I mean, passability is based off of 8 directions, right? So what does the 0x0f or 15 come from?

When I look at this line, it confuses me what its purpose is...

# If obstacle bit is set in all directions
elsif @passages[event.tile_id] & 0x0f == 0x0f


That basically translates to me like...

# If obstacle bit is set in all directions
elsif @passages[event.tile_id] & 15 == 15


0x0f == 0x0f and 15 == 15 will always return true, right? Or does this 'bianary' number change or what? Thanks ahead of time for anybody who can clear that up for me.

@Velocir_X : This topic is for general Ruby/RGSS and RGSS2 questions, ie questions about default scripts and not custom scripts, if I'm not mistaken. Unless you're talking about VX, you might want to make your own support topic with the code for the CMS and especially the parts that you made to deal with facesets. If I have time I'll drop in and try to help you out.

If you want, I have a scriptlette (which needs to be updated) from my CMS which I use to handle face graphics, with a settings module so you can define things like what to look for in the filename when referencing a faceset.

Most people who do their own 'faceset' script for XP would reference it like @actor.character_name + "_face", ie Fighter 01's faceset would be "001-Fighter01_face" for the filename. If it doesn't exist, then use a rescue statement so it doesn't crash the game... please make topic, I'll try to help you more if I have time today.


There is no difference on using 0x0F or 15. Both will do the same thing, as they are both evaluated as the same value.

Your logic missed the boolean operator. It shouldn't be evaluated as:
@passages[event.tile_id] & 0x0f == 0x0f
First, it should be:
@passages[event.tile_id] & 0x0f == 0x0f

The value of "@passages[event.tile_id]" is a number, but on boolean representation it would be composed of four flags:
abcd
Each of them is a direction. I can't guarantee but I believe that a = up, b = right, c = left and d = down.
Anyway, 0x0f is "1111" on boolean. Therefore, all directions checked. When you do the AND operator, it'll check each flag, or bit, and do the AND calculation. AND will only return 1 (aka. true) if both values are 1.
So:
0110 AND
1100 =
0100

What is a mystery is why they're using the AND operator there. Any value you use there "AND" 0x0f will result on the first value, so I guess it could be:
@passages[event.tile_id] == 0x0f
Edit:
Well I changed my mind...

I'm going to use battlebacks for NPC dialouge, essentially going into battle with someone to talk with them...and I want to use battlers to represent each person....

-get battler id
-show battler
-position: L,R,C

is there a way to do this with a basic script command? $sprite.battler? something? idk! help me out please!
Good Evening!!
I've a couple of questions about the Bitmap class
and the various command that this class use i'm trying to calculate the time of execution of the Bitmap's methods
the ammount of RAM and CPU that the Methods use for example... is there an easy way to do it? like a table where all of this is contained
for example... what's the difference between these two Line of code in RAM and CPU:
  1.  
  2. @image = Sprite.new
  3. @image.bitmap = RPG::Cache.picture("image.png") #for an image big n*32 width and m*32 height pxl
  4. #---------------------------------------------------------------------------
  5. @image = Sprite.new
  6. @image.bitmap = Bitmap.new(n*32,m*32)
  7. for i in 0..n-1
  8.   for j in 0..m-1
  9.     img = get_img(i,j)
  10.     @image.bitmap.blt(i*32,j*32,img,Rect.new(0,0,@image.width,@image.height))
  11.   end
  12. end
Expand to see the code.

I'm sure that the second way to do it have a bigger impact on the CPU usage...
but... if i try to do other action on this Sprites...
  1. @image.x = @new_x
  2. @image.y = @new_y
  3. @image.zoom_x = @new_zx
  4. @image.zoom_y = @new_zy
  5. @image.mirror = @boolean_mir
Expand to see the code.

assuming the case where the Sprite called @image is taken from a single PNG file
then the case where the Sprite is created with a merge of more pictures.PNG...
There is here a case where there is a lighter use of the CPU and of the RAM?
or it's the same thing?
there may be the case where n and m (width/32 and height/32 of the @image) are >= 100 for example.

I'll explain what i'm doing (so that you may have a better view of the problem)
I'm rewriting the Tilemap Class ('cause all the version i've seen have a lot of lag or glitch)
I've write a script that create a file .PNG (that will be saved in a directory "Temp") of the first layer of the map, then, when you load that particular map, put the .PNG at the same spot of the not-animated tiles of the first layer (the animated one will be print under the .PNG) the problem of this script is that it takes several seconds to create and save the .PNG (for a map 50x50 it takes 6 seconds) storing the previous Temporary maps, so you don't have to create it everytime, just the first time, and eventually again if you delete the file into the "Temp" directory.

So, does the composed Sprite (with the .bitmap.blt() method) takes the same time to be modified that takes the Sprite created with a single image (also if we're talking about a big image, with a lot of tiles merged together) or not?

==================================================================================

I've another question, always regarding the Bitmaps...
talking about the Animated-Autotiles...
is it easyer for the computer to update the animated graphic of a single tile in a bigger Sprite
or to manage several sprites that will be resetted with the new frame?
  1. @image = Sprite.new
  2. @image = Bitmap.new(n*32,m*32)
  3. #previous code where i create the bitmap... etc...etc...
  4. def update
  5.   n = @image.width/32
  6.   m = @image.height/32
  7.   for i in 0..n-1
  8.     for j in 0..m-1
  9.       for z in 0..2
  10.       if animated #if an animated autotile is detected in i,j,z coords
  11.       new_anim = get_autotile(i,j,z)
  12.       @image.bitmap.blt(i*32,j*32,new_anim,Rect.new(0,0,@image.width,@image.height)
  13.       end
  14.     end
  15.   end
  16. end
  17.  
  18. #-------------------------------------------------------------------------------------------------------
  19.  
  20. @tiles = {}
  21. n = @map_data.xsize
  22. m = @map_data.ysize
  23. for i in 0..n-1
  24.   for j in 0..m-1
  25.     for z in 0..2
  26.       coords = [i,j,z]
  27.       @tiles[coords] = Sprite.new
  28.       @tiles[coords].bitmap = get_autotile(i,j,z) #or the relative Tile, i can't go into the specifics here XD
  29.       @tiles[coords].x = i*32
  30.       @tiles[coords].y = j*32
  31.     end
  32.   end
  33. end
  34. #then, for the method update
  35. def update
  36.   n = @map_data.xsize
  37.   m = @map_data.ysize
  38.   for i in 0..n-1
  39.     for j in 0..m-1
  40.       for z in 0..2
  41.         coords = [i,j,z]
  42.         if animated(coords)
  43.           new_autotile = get_autotile(i,j,z)
  44.           @tiles[coords].bitmap = new_autotile
  45.         end
  46.       end
  47.     end
  48.   end
  49. end
Expand to see the code.


I know for sure that to handle several Sprites is a bigger issue for the program... but i don't know if to edit a sector of a Bitmap (with .bitmap.blt()) is easy like setup a new image for the Bitmap (with .bitmap = var) do someone know the answer?

So... resuming all of this:
a single big bitmap (created with a picture, a file taken from a directory) called single_bitmap
a big bitmap (created merging several images, with the .bitmap.blt() method) called composed_bitmap
When the 2 images has been created... to edit single_bitmap is like edit the composed_bitmap? the RGSS think at the two of them like 2 simple images? the composed_bitmap is processed as a single image or as a composition of several images (also after the creation)?
and... the .bitmap.blt() method has the same CPU and RAM usage of the command .bitmap = var... or the second one is lighter? (delay of bitmap.blt() >> delay of bitmap = var)
is preferred to handle several Sprites, so that you can modify them one by one... or to handle a single composed Sprite that you have to edit?

Obviously if a composed_bitmap for the RGSS is still a group of several bitmap (and not a single image)... then the answer to the second question is immidiate ^_^
Thanks!! I really hope for an answer!!
i Hope this wont be considered a Double Post... since long time has passed from my last post (also if it's still the last of the topic)

i was asking you about an algoritm and a solution to a question of mine... i'm trying to make a Method for Bitmap, that draw a Graduated text
  1.  
  2.   def draw_gradient_text(x,y,w,h,text,color1,color2,align = 0)
  3.     text_bitmap = Bitmap.new(w,h)
  4.     text_bitmap.font.name = self.font.name
  5.     text_bitmap.font.size = self.font.size
  6.     output_bitmap = Bitmap.new(w,h)
  7.     old_color = color1
  8.     for i in 0..h-1
  9.       new_red = (old_color.red*(h-i-1) + color2.red)/(h-i)
  10.       new_green = (old_color.green*(h-i-1) + color2.green)/(h-i)
  11.       new_blue = (old_color.blue*(h-i-1) + color2.blue)/(h-i)
  12.       new_alpha = (old_color.alpha*(h-i-1) + color2.blue)/(h-i)
  13.       old_color = Color.new(new_red,new_green,new_blue,new_alpha)
  14.       text_bitmap.clear
  15.       text_bitmap.font.color = old_color
  16.       text_bitmap.grad_draw_text(0,0,w,h,text,align)
  17.       output_bitmap.blt(0,i,text_bitmap,Rect.new(0,i,w,1))
  18.     end
  19.     self.blt(x,y,output_bitmap,Rect.new(0,0,w,h))
  20.   end
  21.  
Expand to see the code.

this is the solution that i've found... but i consider it a little bit expensive, also not so good to see... extra bitmaps and all the rest...
do someone know a better way? or maybe a way to clean what i've write here?
probably the solution is in the right use of rect... but i don't know how...
thanks!! :)


aaand... how do i write the syntax for this?
I'm the text of a window message
this \gr[1][2]word\gr is graduated
i know that this:
@text.gsub!(/\\[Gg][Rr]\[([0-9]+|#[0-9A-Fa-f]{6,6})\]/) { "\016[#{$1}]" }
will turn the string \gr[n] into \016, and will save as $1 the value of n
but what if i want to put 2 value in the string between []?
what do i have to write? i've searched around for the string syntax without results... and i've no idea how they work...
i made this work only because i've copied from another script... what i want to do is:
\gr[n][n] (where N could be a color code or an integer) and save both the [n] in 2 var called $1 and $2
i know that it's possible, i simply don't know the syntax for this operation... thanks again!! :D
Am I right in thinking else is Ruby's equivalent of default in switches?

As in:

case variable
when 1
# do this
when 2
# do that
else
# do something completely different
end
Princess Amy wrote:
Am I right in thinking else is Ruby's equivalent of default in switches?

As in:

case variable
when 1
# do this
when 2
# do that
else
# do something completely different
end

Think of the Ruby switch statement as a "when" statement, it's very different to the computer science standard switch statement.

Switches are a safe replacement of the original goto statement, this would be the equivalent switch;

  1.  
  2. switch ( variable ) {
  3. case 1:
  4.     // Do this
  5.     break; // <-- Notice this
  6. case 2:
  7.     // Do that
  8.     break; // <-- Notice this
  9. case default:
  10.     // Do something completely different
  11.     break; // <-- Notice this
  12. }
  13.  
Expand to see the code.


However this switch statement is completely different;
  1.  
  2. switch ( variable ) {
  3. case 1:
  4.     // Do this
  5. case 2:
  6.     // Do that
  7. case default:
  8.     // Do something completely different
  9. }
  10.  
Expand to see the code.

In that last case, the default will always get called and case 2 is called after case 1 then default is called after that, this can't be done with Ruby, you'd have to do this to get the equivalent for that last C code;
  1.  
  2. case variable
  3. when 1, 2
  4.     # Do this
  5.     if variable == 2
  6.         # Do that
  7.     end
  8. end
  9. # Always do something completely different
  10.  
Expand to see the code.


So Ruby's version of default is whatever comes after the switch statement, to give this the "break" operation you need to check that nothing else will be called;
  1.  
  2. doDefault = true
  3. case variable
  4. when 1, 2
  5.     doDefault = false
  6.     # Do this
  7.     if variable == 2
  8.         # Do that
  9.     end
  10. end
  11.  
  12. if doDefault == true
  13.     # Do something completely different
  14. end
  15.  
Expand to see the code.





(For the old school) This is what the switch statement replaces;
  1.  
  2. if ( variable == 1 ) {
  3.     goto CASE_1;
  4. } else if ( variable == 2 ) {
  5.     goto CASE_2;
  6. }
  7. goto CASE_DEFAULT;
  8. CASE_1:
  9. goto CASE_END; // <- This would be the "break" keyword
  10. CASE_2:
  11. CASE_DEFAULT:
  12. // Default always called and called when ( variable == 2 )
  13. CASE_END:
  14.  
Expand to see the code.

In fact you'll find that C compilers will complain for when you declare a variable inside a switch statement because it abuses the stack that the goto statement would ruin (You would miss the declaration, this is why C90 and earlier needed you to declare your variables at the top of the stack), you need to make a new block {} within the statement for any variables you declare.

Edit: Turns out Ruby's when statement is weaker than I thought it was, updated the code where I had "when 1, 2 when 2"
Thank you, really insightful.
Princess Amy wrote:
Thank you, really insightful.

I was incorrect on a part of it, the Ruby case is just an if elseif else wrapped into one, you can't even make it emulate a switch statement without removing it until there is 1 case left.
Bit of a weird one. Probably an obvious answer (hopefully). Wondering if anyone's come across this.

Basically I'm spawning events, using Game_Event.new. I set it up, based on an existing event, and it does appear... but it has no graphic. I can check it's .character_name, and it returns "001-Fighter01", but it's just transparent as an event.

If I open and close the menu, the event appears.

What do I need to update or refresh that I'm missing do you reckon?

  1.  
  2. class Game_Map
  3.   def add_event(map_id,id,x,y)
  4.     s = 1
  5.     (1..@events.size + 1).each{|s|break unless @events.keys.include?(s)}
  6.     map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
  7.     ev = map.events[id]
  8.     ev.id = s
  9.     @events[s] = Game_Event.new(@map_id, ev)
  10.     p @events[s].character_name
  11.     @events[s].moveto(3, 3)
  12.     return @events[s].id
  13.   end
  14. end
  15.  
Expand to see the code.


Adds an event and returns it's ID.
it needs to get added to the list of events in Spriteset_Map. It's an array of Sprite_Character, one for each event on the map, and it only gets modified on map load (thus, showing up when going to and from menu).
Cheers, forgot about the spriteset.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=33070