(Regular Expression) Letter Count - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Games Development (https://www.save-point.org/forum-4.html) +--- Forum: Code Support (https://www.save-point.org/forum-20.html) +--- Thread: (Regular Expression) Letter Count (/thread-5062.html) |
(Regular Expression) Letter Count - MechanicalPen - 03-13-2014 So long story short, I have this script in my game's message boxes that pauses rendering for a bit after a . ! or ? (A sentence-by-sentence script instead of letter-by-letter) The regular expression that does this is: Code: @text.gsub!(/([?.!][^\n\z"])/) { "#{$1}\005[#{$game_system.message.end_delay}]" } I want to change it so the pause before the next sentence to be based on the length of the sentence. How would I modify this regular expression to capture the sentence length into a variable? RE: (Regular Expression) Letter Count - DerVVulfman - 03-14-2014 The returned value of @text... is that the segment that will print, or the leftover text of the previously saved text (thinking the latter). I'm at work so Pseudo-Code here: Code: old_length=@text.size RE: (Regular Expression) Letter Count - MechanicalPen - 03-15-2014 The gsub! method just replaces all instances of .!? with .\005[4] !\005[4] ?\005[4] which is my control code for "stop text rendering for a bit (4 frames)" it works exactly like all the other special codes for gold, hero name, etc. So printed_length in this case would always return 7. I need to come up with a different solution, possibly capturing the sentence into $2 and using that as the frames to wait. Edit: 10 minutes of playing around on http://rubular.com/ got me to /(.+?)([?.!][^\n\z"])/ so Code: @text.gsub!(/(.+?)([?.!][^\n\z"])/) { "#{$1}#{$2}\005[#{$1.length}]" } RE: (Regular Expression) Letter Count - DerVVulfman - 03-15-2014 That could work. Better than having to use an old_style parse (from X to Y) technique. Man, it's been months since I handled @gsub replacement stuff for messages. |