Dekita, actually that would add the entirety of $text to the document again, along with your edits. So there'd be duplicate data within your log.
Shaz, if you'd like to add to it, just do like Ruby 1.8.X and just open the file and append text. I would not leave a file handle open like that though, it's too risky; it isn't good practice. It would be better to just do something like this:
module MyLog FileName = "Data/MyLog.txt" def self.append(text) File.open(FileName, 'w+') {|doc| doc << text } end def self.overwrite(text, offset = 0) File.open(FileName, 'w') {|doc| doc.seek(offset); doc.write(text) } end def self.read(offset = 0) File.read(FileName) endendIf you must keep a handle to the file open constantly, I would suggest using File#sync and/or wrapping the entire rgss_main in a begin..rescue..end clause to ensure that the file handle is closed upon exit. Or something.
Consider using the append mode, 'a', when writing to the file. That way you only need to use the file for relative short amounts of time. I dunno if you can use that option on File::write.
*hugs*
@FenixFyreX
I am unsure as to why my method wouldnt work ? i re-checked the definition of the "w+" arguement and it is defined as follows...
"r+": Sets the read-write position to the beginning of the file."w+": The same as "r+", but if a file already exists when file is opened, the previous file's contents will be deleted. Therefore, each time you write to the file is should remove the previously created file and just re-write all data now stored in the $text variable?
Anyone know why this wouldn't be the case? im confused now 😛
Edit:
as Zeriab also mentioned,
you could simply use File.open(doc_name, "a") { |d| d << "crap" }
Note: File.open opens and then reads / writes (depending on arguments) and then closes the file. ( this only works if a block is passed to the method)
I'm sorry, my fault for my typo. I meant to write 'a' like Zeriab suggested. You aren't required to lug around a large String within a global variable when you do that, you simply append the text to the document. Thanks, Zeriab.
Also, as I stated before, it is good practice to keep less objects in memory space as possible, even with Ruby. Actually, especially with Ruby. Ruby's garbage collector isn't the best and writing clean, tidy and organized code is much more preferable. While a few loose strings here and there (read: one loose File handle) won't affect performance, keeping all your objects in check can be the difference between 60 FPS and 6, but I digress; I'm just ranting now. 😛
Dekita, I did not intend to target you or your code; I'm simply trying to explain why managing your objects and implementing a bit of encapsulation is more preferable to outright global variables, that's all. 🙂 Your code definitely would work.
@File.read, if you modularize your code and write a few methods instead of needing to add text dynamically directly within the file handle, it'll help people understand your code as well as yourself further down the road
No worries, i did not feel targeted or anything like that.
I was just a little confused as to why it would keep the existing text within [x] document when opening and using the "w" or "w+" to overwrite it. (it doesnt, i tested 😛 )
Edit: also as Ice Dragon stated, its pointless to open the file with read capabilities if the whole file is being overwritten, so "w+" is less efficient than "w" 😛
I only use this for debugging purposes, so I don't mind it a bit messy like that. I'd never release it with something like that in (unless I needed debug logs from beta testers as well).
Thanks for the tips 🙂
Previously I wanted a script that calls an event on the map.
For example:
$game_map.events[id].set_graphic("character_name", character_index)Now there's a question: how could I temporarily stop this event from moving, without stopping all other event processing? If I tried using script equivalent of wait, it stopped everything including the player.
What are you trying to accomplish, and why are you doing it via scripting?
Due to author's terms of use I cannot post any part of the script here. It's Khas' ABS system. Enemies there are visible on map as events.
What I'm trying to do is make enemy "stunned" for a second or two when they get hit by a player. I just hoped it would be something simple but if it's complicated then it's ok 🙂 Maybe I'll think of something else.
Okay peoples...I am using RMVX (not ACE), and I'm wanting to change when the actors health becomes 'in critical condition' from 25% to 50%... I've been looking all over the scripts to find out where this is defined and I can't seem to locate it. I was hoping someone familiar with RMVX and Ruby SS2 could help me out here and at least point me at the particular script and the lines where the game defines this. Or...I suppose if it's more difficult than I thought...some kind of work-around that would allow this. I have scripts that would change the battler sprite when critical...but I'd like to change what % of HP that is...I hope this makes sense and would appreciate the help. Thanks.
@Kurisu, do you have to do this via scripts? If it were an event, I'd just turn on a self switch on the event to swap it to a new page with the graphic but no attack commands, and after X frames, turn the self switch off again. Or I'd start with that and work from there. To know how the events really behave, you'd need to give us a link to the script.
@kingmakerspider, in Window_Base, the methods hp_color (line 205) and mp_color (line 214) return crisis_color if the actor's hp or mp is less than their max hp or mp / 4. To change it to 50%, just change the 4 to 2 on both of those lines.
@Shaz sadly it has to be done via script, yes 🙂 My request is blowing out of proportions though, I already feel bad for asking so many questions... You do have good idea with self switches, perhaps it would be possible to toggle a self-switch via script command? I will try it this way. There are also two scripts that seem to be expanding self-switch functionality, I might try using them too.
$game_self_switches[[map_id, event_id, 'A']] = true/false
is how you change self switches via script.
If it's turning into a big thing, I'd suggest starting your own thread, because it probably no longer falls under the "... Questions that don't deserve their own thread" category anymore 🙂
Thanks Shaz! That helped me with half of it but using that as a clue I was able to fix it in all my combat scripts...for some reason they use different terminology than the original "Crisis" in some scripts. In the scripts I'm using, it ended up being defined as "pinch", go figure. But I figured it out thanks to you! I appreciate it.
Regular expressions are the bane of my life! Could someone help me out with this one, please?
I want to take a string that contains any number of \v[x] patterns (where x is a number with 1 or more digits), and pull out an array of all of the numbers. The string may or may not have other text (including spaces) before, between and after these patterns.
So both of the following
test \v[1] test \v[2] test \v[3] test
\v[1]\v[2]\v[3]
will result in
[1, 2, 3]
Edit: nevermind ... got it, after much mucking around.
patt = /\\v\[(\d+)\]/i
str = %q[test \v[1] test \v[2] test \v[3] test]
p str.scan(patt).flatten.map {|val| val.to_i}