Posts: 422
Threads: 23
Joined: Aug 2011
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?
Posts: 11,261
Threads: 651
Joined: May 2009
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
@text.gsub(/([?.!][^\n\z"])/) { "#{$1}\005[#{$game_system.message.end_delay}]" }
new_length=@text.size
printed_length = old_length - new_length
Note that I used
gsub and not
gsub! so I don't actually 'CUT' the string. That would be for later when you do the printing of the message.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links
Posts: 422
Threads: 23
Joined: Aug 2011
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}]" }
Works with $2 containing the .!? character and $1 containing the sentence.
Posts: 11,261
Threads: 651
Joined: May 2009
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.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links