Thank you so much! That did the trick.
Ruby/RGSSx questions that don't deserve their own thread
RGSSx Script SupportIn VX, we can sets up new area that handles encounters. What I wonder is, how to call the name of an area via script/scriptcall?
You'd probably be able to look at VX's Game_Map (or maybe Game_Player if it's for encounters) to see how it's handled, and just do the same thing.
I can't seem to figure this one out...
Maybe there is an easy way to do it, so I will try my luck here.
So, let's say I got an array of arrays, like this:
big_array = [["HP.Reg: ",0.03],["MP.Reg: ",-0.01],["FP.Reg: ",-0.01]]How could I determine the last value from the last array in the big array?
I mean, I know it is big_array[2][1], but how could I make a conditional branch on that?
Like 'if it is the last value from the last array do this, else do that'?
Is there any way to do this?
Simply putting 'if value == big_array[2][1]' will not work, because there are some identical values occasionally.
I want to put a comma after each small arrays displayed but not after the last one, and whatever I try, it just won't work. >.>
My conditional checks only work if there are no identical numbers in the small arrays or when the big_array's size is not more than 2. No idea why it works when the size is 2 and doesn't work when the size is more than 2.
Can anyone help me in this, pretty please? *-*
Edit:
Ok, I finally managed to make this work with adding a new variable which increases after each number draw, and I could easily make a condition with that variable.
But I still wonder, is there any other way to determine the last value of an array?
Maybe there is an easy way to do it, so I will try my luck here.
So, let's say I got an array of arrays, like this:
big_array = [["HP.Reg: ",0.03],["MP.Reg: ",-0.01],["FP.Reg: ",-0.01]]How could I determine the last value from the last array in the big array?
I mean, I know it is big_array[2][1], but how could I make a conditional branch on that?
Like 'if it is the last value from the last array do this, else do that'?
Is there any way to do this?
Simply putting 'if value == big_array[2][1]' will not work, because there are some identical values occasionally.
I want to put a comma after each small arrays displayed but not after the last one, and whatever I try, it just won't work. >.>
My conditional checks only work if there are no identical numbers in the small arrays or when the big_array's size is not more than 2. No idea why it works when the size is 2 and doesn't work when the size is more than 2.
Can anyone help me in this, pretty please? *-*
Edit:
Ok, I finally managed to make this work with adding a new variable which increases after each number draw, and I could easily make a condition with that variable.
But I still wonder, is there any other way to determine the last value of an array?
To get the index of the last item in the array you can always do array[-1]
so if value == big_array[-1][-1] would be the last element inside the last element. However, like you said, sometimes you can have values that will be the same. So i'd probably do something like
for i in big_array
do code
end
So it runs through the array. And then you could put a check in to say add the comma unless i == (big_array.size - 1)
so if value == big_array[-1][-1] would be the last element inside the last element. However, like you said, sometimes you can have values that will be the same. So i'd probably do something like
for i in big_array
do code
end
So it runs through the array. And then you could put a check in to say add the comma unless i == (big_array.size - 1)
What do identical values have to do with anything?
SHOW us what you're trying to do - give us the code you're using, explain your goal. Understanding what you're trying to achieve will let us advise you better (and maybe indicate that you're not going about it in the best way).
You're talking about displaying an array and putting commas, but that's not something you normally do as far as the player is concerned, and doesn't really explain how you want it to appear to the player.
SHOW us what you're trying to do - give us the code you're using, explain your goal. Understanding what you're trying to achieve will let us advise you better (and maybe indicate that you're not going about it in the best way).
You're talking about displaying an array and putting commas, but that's not something you normally do as far as the player is concerned, and doesn't really explain how you want it to appear to the player.
I don't display an array as is, obviously. 😀
I draw the values in the arrays with draw_text.
I separated strings, and numbers in the small arrays, because I need to do some math on the numbers before displaying them.
My big array looks something like this:
This is just an example of my big array (maybe even too many, lol).
Anyway, as you can see, the size of each array varies, and even the size of the smallest arrays can vary (like the "locked/unlocked" example).
So, I displayed all these in a help window. Each index of the 'VALUES' array corresponds to a "Mastery" (see the screenshot for an example) in the scene.
For displaying this piece of information, I used something like this:
This works exactly how I want it to work.
It puts commas only after the numbers from the array, and only if it is not the last number from the last small array.
My problem was here, and it originated because, as you can see, I got some identical values in certain cases, so I couldn't simply tell 'if value == VALUES[index][id.size-1][1] then do this, else do that', because that would return true for all values equal to the last element in the last array.
Then I made the '@comma' variable and solved the issue.
I have no idea if this was the most efficient solution for this (probably not 😛 ), but it works. I am making this scene for personal use only, so as long as it works and got no FPS issues, I am satisfied with it.
But for possible future usage and out of curiosity, I wanted to know if there are any easier methods for this.
And this is how it looks right now:
http://www.mediafire.com/view/7voy5m7rmkvewzt/exmpl1.PNG
http://www.mediafire.com/view/lksu4oz2ffshq67/exmpl2.PNG
The scene is from AdiktuzMiko's Custom Attributes script, heavily modified by me, and not finished yet with it.
So, how could this be done easier?
@Venka
I always forget about the 'for ... in ...' method.
But isn't this the same as the 'X.each do |y| ...' method?
Because in those rare occasions when I used the 'for' method, it did exactly the same as the 'each do' method. Which is why I rarely use it.
But maybe I am missing something. I will look into this further now, thanks for the info! 🙂
I draw the values in the arrays with draw_text.
I separated strings, and numbers in the small arrays, because I need to do some math on the numbers before displaying them.
My big array looks something like this:
VALUES = [] VALUES[0] = [["MaxHP: ",0.05]] VALUES[1] = [["P.Dmg: ",0.05]] VALUES[2] = [["P.Dmg: ",0.05]] VALUES[3] = [["A.Speed: ",0.02],["M.Speed: ",0.02]] VALUES[4] = [["M.Dmg: ",0.05]] VALUES[5] = [["Ch.Time: ",-0.03]] VALUES[6] = [["Cri: ",0.01],["Hit: ",0.01]] VALUES[7] = [["Cri: ",0.01],["P.Dmg: ",0.03]] VALUES[8] = [["Cri: ",0.02],["R.Speed: ",0.02]] VALUES[9] = [["C.Dmg: ",0.01],["MaxMP: ",0.02]] VALUES[10] = [["Cri: ",0.01],["Hit: ",0.02]] VALUES[11] = [["C.Dmg: ",0.03],["P.Dmg: ",0.01]] VALUES[12] = [["Eva: ",0.01],["Counter: ",0.01]] VALUES[13] = [["P.Dmg.Res: ",0.01]] VALUES[14] = [["M.Dmg.Res: ",0.01]] VALUES[15] = [["Counter: ",0.01]] VALUES[16] = [["Fire Res: ",0.03],["Ice Res: ",-0.01],["Water Res: ",-0.01]] VALUES[17] = [["HP.Reg: ",0.01],["MP.Reg: ",-0.01],["FP.Reg: ",-0.01]] VALUES[18] = [["Skill: ","Locked!", "Unlocked!"]] VALUES[19] = [["Holy Att.Rate: ",0.3]]
Anyway, as you can see, the size of each array varies, and even the size of the smallest arrays can vary (like the "locked/unlocked" example).
So, I displayed all these in a help window. Each index of the 'VALUES' array corresponds to a "Mastery" (see the screenshot for an example) in the scene.
For displaying this piece of information, I used something like this:
@help_window.draw_text(@tx,0,@help_window.width-standard_padding*2,line_height,"( Current Bonuses → ") @tx1 = @tx + text_size("( Current Bonuses → ").width @tx2 = 0 @comma = 0 VALUES[index].each do |id| id.each do |value| if value.is_a?(Integer) @result = (value * (@actor.custom_attribute(index))).to_s + ", " # I still need to do the comma check for the integer numbers here just like at the float values... elsif value.is_a?(String) && (value != "Locked!" || value != "Unlocked!") @result = value elsif value == "Locked!" && @actor.custom_attribute(index) > 0 @result = "" elsif value == "Locked!" && @actor.custom_attribute(index) == 0 @result = "Locked!" elsif value == "Unlocked!" && @actor.custom_attribute(index) > 0 @result = "Unlocked!" elsif value == "Unlocked!" && @actor.custom_attribute(index) == 0 @result = "" elsif VALUES[index].size == 1 || (VALUES[index].size > 1 && @comma == VALUES[index].size-1) @result = ((value * 100 * (@actor.custom_attribute(index))).to_s + "% ") else @comma += 1 @result = ((value * 100 * (@actor.custom_attribute(index))).to_s + "%, ") end @help_window.draw_text(@tx1+@tx2,0,@help_window.width-standard_padding*2,line_height,@result) @tx2 += text_size(@result).width end end @help_window.draw_text(@tx1+@tx2,0,@help_window.width-standard_padding*2,line_height,")")
It puts commas only after the numbers from the array, and only if it is not the last number from the last small array.
My problem was here, and it originated because, as you can see, I got some identical values in certain cases, so I couldn't simply tell 'if value == VALUES[index][id.size-1][1] then do this, else do that', because that would return true for all values equal to the last element in the last array.
Then I made the '@comma' variable and solved the issue.
I have no idea if this was the most efficient solution for this (probably not 😛 ), but it works. I am making this scene for personal use only, so as long as it works and got no FPS issues, I am satisfied with it.
But for possible future usage and out of curiosity, I wanted to know if there are any easier methods for this.
And this is how it looks right now:
http://www.mediafire.com/view/7voy5m7rmkvewzt/exmpl1.PNG
http://www.mediafire.com/view/lksu4oz2ffshq67/exmpl2.PNG
The scene is from AdiktuzMiko's Custom Attributes script, heavily modified by me, and not finished yet with it.
So, how could this be done easier?
@Venka
I always forget about the 'for ... in ...' method.
But isn't this the same as the 'X.each do |y| ...' method?
Because in those rare occasions when I used the 'for' method, it did exactly the same as the 'each do' method. Which is why I rarely use it.
But maybe I am missing something. I will look into this further now, thanks for the info! 🙂
So you basically need to check if it's the last member of the array or not?
Index of -1 returns the last member of the array if I remember correctly, so you could try to just compare the current value to the value of in the -1 index to know if ur on the last index... By comparing value, I mean compare the array not just the integer/float...
so it would be like
VALUES[index].each do |id| id.each do |ary2| if id == VALUES[index][-1] #DONT PUT COMMA end endendBasically we're comparing the array itself, so for example, in VALUES[0] this would check if the current array is equal to ["MaxHP: ",0.05].Or instead of iterating via each, you can iterate via .each_index so that you can check if the index is equal to the size - 1
Index of -1 returns the last member of the array if I remember correctly, so you could try to just compare the current value to the value of in the -1 index to know if ur on the last index... By comparing value, I mean compare the array not just the integer/float...
so it would be like
VALUES[index].each do |id| id.each do |ary2| if id == VALUES[index][-1] #DONT PUT COMMA end endendBasically we're comparing the array itself, so for example, in VALUES[0] this would check if the current array is equal to ["MaxHP: ",0.05].Or instead of iterating via each, you can iterate via .each_index so that you can check if the index is equal to the size - 1
Code:
VALUES[index].each_index do |id| VALUES[index][id].each do |ary2| if id == VALUES[index].size - 1 #DONT PUT COMMA end endend
That's exactly what I have been looking for Adik!
Thanks a lot!
I think I tried to compare the arrays themselves before, but seems like I made a mistake, because that time it didn't work.
Now I tried it again after my morning coffee and double checking everything and it works indeed. 🙂
I reworked the way I made the text display, so instead of dividing the small arrays into separate values and then display the values themselves, I decided to display the whole small array at once and put the extra stuff only after them (like the commas, percentage sign, etc) if it is needed.
I did this because I colored the text for the numbers, green for positive bonus and red for negative, and the way I did before, it colored the commas too, which looks weird to me.
Finished with this scene too, finally! 😀
Thanks again for the help and for the great script!
Thanks a lot!
I think I tried to compare the arrays themselves before, but seems like I made a mistake, because that time it didn't work.
Now I tried it again after my morning coffee and double checking everything and it works indeed. 🙂
I reworked the way I made the text display, so instead of dividing the small arrays into separate values and then display the values themselves, I decided to display the whole small array at once and put the extra stuff only after them (like the commas, percentage sign, etc) if it is needed.
I did this because I colored the text for the numbers, green for positive bonus and red for negative, and the way I did before, it colored the commas too, which looks weird to me.
Finished with this scene too, finally! 😀
Thanks again for the help and for the great script!
Is there a command in RPGMaker to fill a rectangle from the bottom up? For instance I'm trying to make it so that HP bars are vertical instead of the default horizontal, with full to the top meaning 100% HP and empty meaning 0% HP. Can this be done with a simple command call to contents.something?
Help -> Bitmap ->
Code:
gradient_fill_rect(x, y, width, height, color1, color2[, vertical])gradient_fill_rect(rect, color1, color2[, vertical]) Fills in this bitmap box (x, y, width, height) or rect (Rect) with a gradient from color1 (Color) to color2 (Color).Set vertical to true to create a vertical gradient. Horizontal gradient is the default.
No wonder I didn't find it. I was going crazy looking for it under help -> graphics. Thanks!
Using script commands how do I check if an actor being targeted by an enemy has a certain item being equipped?
I tried:
if target.equips[4] == 2
and
if target.equips[4] == $data_armor[2] though this one throws an error.
One more question is could I do this based off the item's name vs it's ID?
Edit: The error message is "undefined method '[]' for nil:NilClass".
I tried:
if target.equips[4] == 2
and
if target.equips[4] == $data_armor[2] though this one throws an error.
One more question is could I do this based off the item's name vs it's ID?
if I remember correctly.. target can be the enemy or the actor, so you'd probably need to check and see if it target is an actor first and then check the equips.
target.is_a?(Game_Actor) will return true if it's an actor
edit: forgot the second part. Yes you can check for it's name or it's ID.
equips should have all the same information as an item. So you'd just check
if target.equips[4].name == $data_armor[2].name
or
if target.equips[4].id == $data_armor[2].id
target.is_a?(Game_Actor) will return true if it's an actor
edit: forgot the second part. Yes you can check for it's name or it's ID.
equips should have all the same information as an item. So you'd just check
if target.equips[4].name == $data_armor[2].name
or
if target.equips[4].id == $data_armor[2].id
Should that work, the following code would be nicer to utilize imo
Code:
target.actor? or target.enemy?
Um ... the actual error would be helpful.
target.equips[slot_id] gives you an RPG::Weapon or RPG::Armor so you can't just say == 2. Also, it's $data_armors, not $data_armor (maybe that's your error message?)
Code:
if target.equips[4].name == "Magnificent Shield"
Code:
if target.equips[4].id == 2
if target.equips[4].id == $data_armors[2].id
I am trying to use this in a formula note tag in a skill that will only be used by an enemy so don't think I will need target.actor?. As far as I am aware I should be able to pass any argument through this note tag as long as it can be scripted correctly.
The part on if I could check the name of the armor was because I am using an item randomization script and not certain how to check the id on items affected by this script (one item affected by this script can potentially be hundreds of items).
Anyway this is just something I have been wondering on. (Don't have to get it working though it would be nice).
Edit: @Shaz yea forgot to put the error message in. It is at the top of this post.
Then the method 'equips' does not exist for whatever target is.
Formula note tag? some script has given you this feature? Do you mean the formula box of a skill?
Formula note tag? some script has given you this feature? Do you mean the formula box of a skill?
Formula note tag basically eval's any scripted command within it. (Formula note tag may be the wrong term for it). And yes the method equips does exist for target as it is working now (my edited above post shows I was missing the s).
Edit: Okay after further testing if the item is one of the randomized items it doesn't work though any item that isn't does. (No error is thrown just won't eval that part of the script). Well anyways think you all for your help.
Edit: Okay after further testing if the item is one of the randomized items it doesn't work though any item that isn't does. (No error is thrown just won't eval that part of the script). Well anyways think you all for your help.
Assumption: You're talking about the box where we put damage formulas
It's simply called Formula Box, not formula note tag...
It's simply called Formula Box, not formula note tag...
This is because the damage eval is kinda enclosed in a rescue set-up so any error would simply stop the whole process and make the damage return nil
Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/