Ruby/RGSSx questions that don't deserve their own thread

Okay wow I'm stoooopid for not trying this a long time ago, but apparently all I had to do was this:

#===============================================================================class Window_Base < Window#===============================================================================#-------------------------------------------------------------------------------# alias draw_actor_simple_status#-------------------------------------------------------------------------------alias :bloodysimplestatus :draw_actor_simple_statusalias :bloodyiniti :initialize   def initialize(*args)    bloodyiniti(*args)    @bloodyscale = BloodPLSS::Scale_Settings    @bloodyx1 = @bloodyscale[😛osi_level1][:x]    @bloodyy1 = @bloodyscale[😛osi_level1][:y]    @bloodyx2 = @bloodyscale[😛osi_power1][:x]    @bloodyy2 = @bloodyscale[😛osi_power1][:y]    @bloodyx3 = @bloodyscale[😛osi_level2][:x]    @bloodyy3 = @bloodyscale[😛osi_level2][:y]    @bloodyx4 = @bloodyscale[😛osi_power2][:x]    @bloodyy4 = @bloodyscale[😛osi_power2][:y]  endAlso my problem was only in a specific part of the code, and I knew where I just didn't know why. I fixed it, but I still don't know why my way didn't weird either. but oooohhhhh well. lol

Now off (after some long earned sleep) to figure out how to make it by class zzzzz.
You might want to start a new topic for this, as this is about a custom script now.

Anyway, I noticed something, which is not relevant to your current error, I guess.

At one place, you are trying to draw an integer. That won't work.

This is the line I am talking about:

draw_text(x, y, 150, line_height, (r / @bloodyscale[:divide]).to_i)That should be:
Code:
draw_text(x, y, 150, line_height, (r / @bloodyscale[:divide]).to_i.to_s)
I rarely use hashes, so I am not sure what is the problem, sorry.And a little tip:

Leave print/p commands where you are not sure what do you need to use and what do you need to convert.

That way you can see what kind of data gets to the specified method and in what form in the console.

This is how I manage to fix most of my problems within seconds, debug number one on my list. 🙂

You can put these commands everywhere you want in a definition, literally.
For the record, passing an integer to draw_text will work, since that method tries to convert to string anything passed as the text argument. 🙂

(So don't use .to_s when passing arguments to draw_text)
Ohh, and it really works like that too. o.o


I always thought that it can draw strings only, lol.


Thanks, now I will need to remove a lot of .to_s! 😀
as long as the type can be converting to string they would work... Unless you're drawing something like

draw_text(1 + "x") #simplified for illustration purposesNow this won't work as far as my experience is concerned since you're trying to add a string to an integerBasically, it will only try to convert the end result, not the intermediates.
Breaking down this "def" just to be 100% on what it is doing

def by_three?(n)    return true if n % 3 == 0 else falseend
return the Boolean(by_three?) as true if n(number) modulo(remainder of n divided by 3) is equal to 0, if not then return false.

I'm pretty sure this is how it is, but I want to make 100% sure, as code academy doesn't explain every little thing like that lol.
That should work. You can drop the "else false" part though as it's not needed. It'll only return true if the equation is true. You could also do

def by_three?(n) n % 3 == 0endfor the same effect. If the equation is true, it'll return true or false if it isn't
Interesting, well it had me doing the return stuff so it made me use that. There are so many ways to do one thing it is quite cool. Lol
yeah, that's one of the things I like about programming 🙂

Just to let you know (because it's handy to know for certain occasions).. return will exit out of the current method.

So say you're running a long method and you know you don't need to run all of the code if one of the variables isn't going to check out.

Like this from the Game_BattlerBase

#-------------------------------------------------------------------------- # * Determine if Equippable #-------------------------------------------------------------------------- def equippable?(item) return false unless item.is_a?(RPG::EquipItem) return false if equip_type_sealed?(item.etype_id) return equip_wtype_ok?(item.wtype_id) if item.is_a?(RPG::Weapon) return equip_atype_ok?(item.atype_id) if item.is_a?(RPG::Armor) return false endthe first line will exit out of the method if the item it's checking isn't and equipable item. Since it can't be equipped.. there's no reason to do the other checks.

it will return a value of "false" so which ever method called this one will know the items can't be equipped.

Also it's used like this from the Game_BaseItem script

#-------------------------------------------------------------------------- # * Get Item Object #-------------------------------------------------------------------------- def object return $data_skills[@item_id] if is_skill? return $data_items[@item_id] if is_item? return $data_weapons[@item_id] if is_weapon? return $data_armors[@item_id] if is_armor? return nil endThis one is checking what type of item an object is. So it checks first if it's a skill, if it is, then it will return the skill item. It then checks if it's a item, weapon, armor and if it's no of those, then it will return a nil value.

Hope I'm not muddying the waters for you.
Yeah I understand that a pretty good amount actually. I think it's all starting to click for me lol.

But holy moley just adding a sub hash and another uhm idk what to call it, but my oh my how did it change my script from making it globally all actors to specifically editing them individually. I think I love hashes lol.
How do I extract n unique random elements from 1..n array?
How do I extract n unique random elements from 1..n array?
Code:
array.sample(array.size)# If the array has duplicated elements:array = [1, 2, 2, 2, 3, 4, 5, 10]uniq = array.uniquniq.sample(uniq.size)
array.sample(array.size)
Doesn't this sample all of the array elements?

Perhaps I asked the wrong question... I meant to say, if I have [1, 2, 3, 4, 5, 6] array with no duplicates, how do I extract a range of at minimum one random element, and at maximum a number of unique random elements equal to the size of the array?

The result should be something like [3] / [5, 2, 4] / [6, 4, 3, 5, 2, 1]
array.sample(array.size)
Doesn't this sample all of the array elements?

Perhaps I asked the wrong question... I meant to say, if I have [1, 2, 3, 4, 5, 6] array with no duplicates, how do I extract a range of at minimum one random element, and at maximum a number of unique random elements equal to the size of the array?

The result should be something like [3] / [5, 2, 4] / [6, 4, 3, 5, 2, 1]
Code:
array = [1, 2, 3, 4, 5, 6]p array.samplep array.sample(3)p array.sample(array.size)
In addition to what Source has you can do this:

array = [1, 2, 3, 4, 5, 6]p array.sample(rand(array.size))This will call random id's from the array has them sorted randomly and doesn't matter what size the array is (as it calls rand on the size of the array). *note that it can also get an empty array sometimes.
How do I extract n unique random elements from 1..n array?
 
array.sample(array.size) Doesn't this sample all of the array elements?
lol, yes, because you said your array was n elements long, and you wanted to extract n elements. If you didn't want ALL of them, you should have used different letters 😉

Sarlecc's example could be changed to always provide at least one result by changing it to this:

Code:
p array.sample([1, rand(array.size)].max)
lol, yes, because you said your array was n elements long, and you wanted to extract n elements. If you didn't want ALL of them, you should have used different letters 😉
Oh that's why it didn't make sense, I didn't intend the second n to automatically be the same as the first n although it was also a possibility.

Of course I should have used different letters...  :blush:

Thanks guys.
I am gona ask this here because I have a feeling no one wants anymore xasabs topics mine was a general discussion last time not a support thread this question however is a support question and since XASABS has appeared alot I figured it would be better for the community as a whole that I ask for help here.


I am using RMXP, need someone to please help me learn XASABS tool creation. I created the weapon using the skill tab like is instructed and I created a map event with an ID and I created a script part in the XAS weapons tab and well my weapon did not register. 

Please help me using skype,teamviewer,google hangout,or

Rewrite the tutorial with more detail then what the site xasabs.wordpress.com gave I may be over thinking this but I feel as if they didn't put hardly any detail for this. Only my personal feelings and I do not intend to insult the site and say the tutorial sucks because 1 guide might not work for me but will definatley work for others.
Sorry - that is NOT a question that does not deserve its own thread. You already have a thread for this - let's keep it in a single place.
I do not but I still accept the answer no,staff misunderstood the thread I was simply talking about it yes while I mentioned in the comment post about the tutorial lacking the rest was all hype and I was still trying to hard to do it myself at the time I had not intention of asking for help yet. Thank you for your time though :0
then start another thread in Script Support. The purpose of this thread is for simple questions that have simple answers, and usually external scripts don't fall into that category.

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/