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

Does anyone have an idea how to get the original positions of an actor is? For example, I changed the party leader from Eric to Ernest. How do you determine their positions? Because I want to put some function when they change their index.
$game_actors[id].index will tell you what position that actor is in the party. 0 is leader.


I wasn't really sure if THIS is what you were asking, or what was explained in the post above.
$game_actors[id].index will tell you what position that actor is in the party. 0 is leader.

I wasn't really sure if THIS is what you were asking, or what was explained in the post above.
Yes, kinda close. This is basically what I needed to know, for example, I set up a list of states to be applied per actor:

if Eric is the leader, apply this state.

if Ernest is the leader, apply this state.

🙁
You could use both ways, they're just a bit different logic.


The first method (the one on the previous page) is like:


If the leader is Eric, do this


If the leader is Whoever, do this


The second (Shaz' method) is just like


If Eric is leader, do this


If whoever is leader, do this
Thanks. Okay so I forgot if I asked this before, but how can I extract the values of this hash?

State = { 1 => [1, 2, 3, 4, 5, 6, 7] }since it is an array value, how can I extract those?
State[1]Will return the array, so if you wanted, say, the third element in the array, you would write:

Code:
State[1][2] # Array indexes start at 0, so the third element is index number 2
Thanks Kaelan. Another quick question, is there a substitute or a better way to print out documents on a file? For example, I uses syswrite:

targa = File.new("input.txt", "r+") if targa targa.syswrite("Marry had a little lamb") else puts "Unable to open file!" endNow of course, it is understandable that you need to have the input.txt on your game folder. So my questions would be:

How can I automatically create the input.txt on my game folder?

How can I append the texts instead of using syswrite that just writes from one line. Because if I want to add :

Mary had a little lamb,little lamb, Marry had a little lamb,little lamb, little lambI don't exactly know how.
http://stackoverflow.com/questions/7911669/create-file-in-ruby
Can anyone help me in this?

So, I have the following hash:

BIG_HASH => { 0 => {contents}, 1 => {contents}, 2 => {contents}, 3 => {contents},# and so on...}So, hashes in a big hash.How can I remove an entire hash from the BIG_HASH?

But not permanently, only temporary to make a check without that specific hash I want to remove.

Is it possible to do?

I make something with 'BIG_HASH.each do |x, y|', which in the end will return 'X' hash from that BIG_HASH.

Then after this check, I would like to do the same thing, but now with '(BIG_HASH - X).each do |x, y|' hash.

And I can't figure it out how could I do this. >.>
hash.delete will delete the value AND return it.

You shouldn't be doing that to constants though - and I don't know if it'd even let you. If it were a variable, you'd do it something like this:

Code:
x = 5removed_value = big_hash.delete(x)... do stuff here with big_hash, now that x is removed ...big_hash[x] = removed_value
Sounds like you need a separate hash to store the removed elements in.

But why do you need to remove things, then immediately re-add them? It sounds like what you're might not be the best solution to whatever problem this code is trying to solve. It's hard to say exactly what to do without more context on the problem, but my guess is you're probably not going about it the right way.
Does anyone know what the largest integer value I can store in a variable in Roby is? I know in C it was around 4 billion (back in the 90's), but am wondering if Ruby is under any such restriction?
Does anyone know what the largest integer value I can store in a variable in Roby is? I know in C it was around 4 billion (back in the 90's), but am wondering if Ruby is under any such restriction?
I don't think there is a limit in Ruby. It doesn't use a fixed number of bytes.
Thanks Shaz, it worked...


But broke my first check. 😀


Yeah, I guess I will need to find another way of checking for the second item from the hash list.


I just want to eliminate the first selected item from the hash list when checking for the second item, because it will stop the second check at the first match from the big hash, and if it is the same as the first item, it won't do anything, even if there are other matching items below the first selected item. I suppose it is because of the return method I use.


Ohh, well, gonna think for a suitable solution.
Oh ... okay. How are you choosing the first item? How are you choosing the second item? Are you just picking them randomly and you don't want the same one chosen twice? If that's the case ...

Code:
keys = BIG_HASH.keyskey1 = keys.delete_at(rand(keys.size))key2 = keys[rand(keys.size)]
then use key1 and key2 as indexes for BIG_HASH to retrieve the values.
No, not randomly.


I am modifying Vlue's Formation Bonus Script to allow multiple formations.


The actors need to be at the right place to activate a formation on the formation scene.


And everything works fine, until the second formation which would be activated is below the first formation on the hash list, in which case it returns no formation at all.


That is my only problem, and gives me a lot of headache.


The checking method is the same for both formations, but the second one only activates if there is an active formation already, and got more checks built in to prevent selecting the same formation as the first one and some other optional checks, which can be enabled/disabled at will (for disabling nested formations, etc).


Tried to eliminate the first formation from the second list with conditional checks, which usually works in '.each do' loops, but for some reason, it does not work here.


I'm not sure that I can explain the checking methods fully in real scripting language.


Basically, I made a copy/paste from the first check, added some extra conditions to it, and that's it.


But just now, I tried with cloning the hash, and when printing out the keys of the new hash after removing the key onto the console, it shows that the key of the first item is indeed removed, yet it will not activate the second formation.


And when printing out the second match (the second formation), it prints out the correct one, yet won't activate it.


Maybe there is another problem I don't see.


Ohh, well, need to go to work now, will try again later.


Thanks for the help!
I suggest you start a new thread, as this is obviously not a simple question with a simple answer, and we are guessing at the solutions based on incomplete information about what you're trying to accomplish.


Provide ALL the details of what you're trying to do. A link to the script, what the hash actually is, and what you're trying to do with it. What are you trying to achieve from the player's point of view?


Please post all of this in a new thread in Script Support.
Hello Everyone!

I am looking for a script that could allow the camera to focus on a chosen event instead of the hero using a script call.

Just like this Script  does but for XP instead of VX Ace.

Thank you!
You have already asked this question. Please don't post the same question in multiple places. Neither place you posted is the correct place - we have a forum specifically for RMXP (RGSS) Script Requests. I have moved your other thread there.
I suggest you start a new thread, as this is obviously not a simple question with a simple answer, and we are guessing at the solutions based on incomplete information about what you're trying to accomplish.


Provide ALL the details of what you're trying to do. A link to the script, what the hash actually is, and what you're trying to do with it. What are you trying to achieve from the player's point of view?


Please post all of this in a new thread in Script Support.
Actually it was so simple to solve, I haven't even thought about it.


I literally banged my head when I saw what I did, lol.


Instead of directly checking for numbers in an array, I did a '.to_s' on them and checked after it.


And of course it returned false, because if I got an array of [1,5,12] and checking for 4, 2 and 15 after I did a '.to_s' on them would recognize 1 and 5 from the "stringed" array as 15. >.>


So much wasted time on my stupidity, rofl. I don't even know why I did it like that.


Thanks for all the help! That hash delete really came in handy!


And with this, I am finished with that script, yay! 😀
I have learned in a tutorial that this is the right way of using the system read for files in RPG Maker:

aFile = File.new("input.txt", "r")if aFile content = aFile.sysread(20) puts contentelse puts "Unable to open file!"endand the right way for system write:

aFile = File.new("input.txt", "r+")if aFile aFile.syswrite("ABCDEF")else puts "Unable to open file!"endHowever, the syswrite only allows me to write one line in the text method. How can I add more lines to it like line 1, line 2, line 3 etc? Another question, how can I make RPG Maker read it and incorporate it to something such as item descriptions etc?

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