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

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I've heard people say Google does not give them everything that's available on the forum, and a forum search is better. But a forum search is limited to words 4 characters and longer, so has that little drawback.


Anyway, I think we're just a tad off topic here ... ;)
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
ok, to bring us steadily back on topic...

Lets say i have a notetag to register a bit of text, shown in a description box.

/<Description:(.*)>/i,It works fine, but does not allow multilines.. ie, two line descriptions.

So, I add the multiline mode into the regexp like so...
Code:
/<Description:(.*)>/im,
Then, I can simply make a new line (press enter) and it will show the two lines of information as intended; however, I am then faced with the issue of...
Each description has '>' at the end. Which indicates it is including that portion of the notetag in with the regexp match.

Now, I have countered this problem by changing..
Code:
$1.to_s# Changed TO"#{$1}".split(/>/).first
This works 100%. I was just wondering how efficient it actually is, AND, if anyone has a better suggestion - or can explain why the '>' is included when using multiline mode.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
if, in your (.*), you put a  ? (so that makes (.*?) ), it will only match up to the next '>'.  example. I can't really remember why at the moment, given the description of what ?'s function is, but I do know it works for that purpose.

Edit: If I had to guess why it works, it'd be that .*? will match zero or 1 of anything, but then the > in the regex leaves .*? jurisdiction, for lack of a better word, thereby ending the matches there.

Oh, and the '>' character is included in multiline because .* matches it, which will then continue going.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
oh damn. I had forgotten all about that website. Thank you for pointing me in its direction. This will save me so much headache :D

Yea, I tested it in the project and it works flawlessly, knew it would as soon as i read the example you gave though :p
Kinda hoped you would be wrong just so my past hour-or-so of headache was justified :(
I knew there would have been a way round it with regexp though.

Been saying for years I should read up some more on regexp and how to utilize it fully :(
Maybe now should be the time to do that :D
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
If I didn't have rubular to tell me my regex's are wrong, I'd spend so much time changing them, booting the game, outputting match info, looking for issues, etc. That website is a godsend for gettign regular expressions right. Even when I'm not writing in ruby, most regular expression formats are the same, so I still use that for basic reference.

Anyway yes, when using the dot and wildcard, adding a ? with it's parenthesis will make it only match until it encounters whatever the next character in your regex is, because then it sees 'I matched zero or one set of characters between 'Description:' and a '>' ', so it stops there. Very useful when creating some things, like extensions to the escape codes in the text box, where the input could be anything.

Speaking of that, once you get to making a feature that will parse things like custom escape codes in the text box, it gets more complicated because the ? will make it stop at the first 'end' character and call it a day. For example, this. At that point, you're better off trying to use a different end character, such as changing [] to <>, since it's less likely to be caught in there.
 

Neok

Veteran
Veteran
Joined
Jul 31, 2014
Messages
45
Reaction score
15
First Language
English
Primarily Uses
Look here for that. If you'd done a search first, you would have found this already.
But that's exactly where I got the script for Show Picture that I'm trying to use. :(

(That is an amazing resource though. Been really helping me figure out a lot of the program's nuances. Come on Enterbrain, why isn't something like this automatically included with Ace?)

Do you mean pictures as the 20 or 50 you can use with event commands? If you do, then write $game_screen instead of screen. Otherwise you probably should create a thread or read some tutorial(s) as this isn't easy to explain (at least for me).
No worries, thanks for giving it a shot. Yeah, I'm trying to do the one that lets you manipulate it with event commands. Doing $game_screen didn't work either. I guess I need to figure out where the script for screen.pictures[] is coming from and try to inherit it somehow?

I looked over other people's code for related functions, and it looks like all of them are using @sprite.bitmap type scripts to show graphics. I'll try messing around with it more, and if I still can't figure it out, I'll post a proper thread.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Game_Pictures is more or less a container. Game_Picture (no s) is where the interesting stuff happens. And Sprite_Picture.


Also check out Spriteset_Map.update_pictures because that's where they get added visually, after you've created the picture object.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
Is there a script call or way to "permanently" change the Events graphic on all pages?

Example:

Event 1 looks like Farmer on 3 pages. After calling the script call to permanently change event graphic, Event 1 looks like Pregnant Lady on 3 pages. If you leave the map and return, Event 1 will still look like Pregnant Lady on 3 pages without the script call.

edit: also,

how would I go about doing a script call through a move route command? In particular the script call "find_path(id, x, y)" from the following script:

#-------------------------------------------------------------------------------
# * [ACE] Khas Pathfinder
#-------------------------------------------------------------------------------
# * By Khas Arcthunder - arcthunder.site40.net
# * Version: 1.0 EN
# * Released on: 28/02/2012
#
#-------------------------------------------------------------------------------
# * Terms of Use
#-------------------------------------------------------------------------------
# When using any Khas script, you agree with the following terms:
# 1. You must give credit to Khas;
# 2. All Khas scripts are licensed under a Creative Commons license;
# 3. All Khas scripts are for non-commercial projects. If you need some script
# for your commercial project (I accept requests for this type of project),
# send an email to nilokruch@live.com with your request;
# 4. All Khas scripts are for personal use, you can use or edit for your own
# project, but you are not allowed to post any modified version;
# 5. You can’t give credit to yourself for posting any Khas script;
# 6. If you want to share a Khas script, don’t post the script or the direct
# download link, please redirect the user to arcthunder.site40.net
# 7. You are not allowed to convert any of Khas scripts to another engine,
# such converting a RGSS3 script to RGSS2 or something of that nature.
#
# Check all terms at http://arcthunder.site40.net/terms/
#
#-------------------------------------------------------------------------------
# * Features
#-------------------------------------------------------------------------------
# Smart pathfinding
# Fast Algorithm
# Easy to use
# Plug'n'Play
# Game_Character objects compatible
# Log tool
#
#-------------------------------------------------------------------------------
# * Instructions
#-------------------------------------------------------------------------------
# Use the following code inside the "Call Script" box:
#
# find_path(id,fx,fy)
# Runs the pathfinder.
# id => An integer, use -1 for game player, 0 for the event that the command
# will be called and X for event ID X.
# fx => X destination
# fy => Y destination
#
# find_path(id,fx,fy,true)
# Call this command if you want the game to wait the moving character.
#
# If you want to enable Pathfinder's logs, set "Log" constant to true.
#
#-------------------------------------------------------------------------------
# * Register
#-------------------------------------------------------------------------------
$khas_awesome = [] if $khas_awesome.nil?
$khas_awesome << ["Pathfinder",1.0]
#-------------------------------------------------------------------------------
# * Script
#-------------------------------------------------------------------------------
class Game_Interpreter
def find_path(char,fx,fy,wait=false)
$game_map.refresh if $game_map.need_refresh
character = get_character(char)
return if character.nil?
return unless Path_Core.runnable?(character,fx,fy)
path = Path_Core.run(character,fx,fy)
return if path.nil?
route = RPG::MoveRoute.new
route.repeat = false
route.wait = wait
route.skippable = true
route.list = []
path << 0x00
path.each { |code| route.list << RPG::MoveCommand.new(code)}
character.force_move_route(route)
@moving_character = character if wait
end
end
class Path
attr_accessor :axis
attr_accessor :from
attr_accessor :cost
attr_accessor :dir
def initialize(x,y,f,c,d)
@axis = [x,y]
@from = f
@cost = c
@dir = d
end
end
module Path_Core
Log = false
Directions = {[1,0] => 3,[-1,0] => 2,[0,-1] => 4,[0,1] => 1}
def self.runnable?(char,x,y)
return false unless $game_map.valid?(x,y)
return false if char.collide_with_characters?(x,y)
$game_map.all_tiles(x,y).each { |id|
flag = $game_map.tileset.flags[id]
next if flag & 0x10 != 0
return flag & 0x0f != 0x0f}
return false
end
def self.run(char,fx,fy)
return nil if char.x == fx && char.y == fy
st = Time.now
@char = char
@start = Path.new(@char.x,@char.y,nil,0,nil)
@finish = Path.new(fx,fy,nil,0,nil)
@list = []
@queue = []
@preference = ((@char.x-fx).abs > (@char.y-fy).abs ? 0x0186aa : 0x01d)
class << @list
def new_path?(path_class)
for path in self
return false if path.axis == path_class.axis
end
return true
end
end
class << @queue
def new_path?(path_class)
for path in self
return false if path.axis == path_class.axis
end
return true
end
end
if @preference & 0x02 == 0x02
@queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)
@queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)
@queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)
@queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)
@list << @start
loop do
break if @queue.empty?
@cpath = @queue[0]
if @cpath.axis == @finish.axis
@finish.cost = @cpath.cost
@finish.from = @cpath
break
end
@list << @cpath
@path_array = []
p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])
p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])
p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])
p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])
@path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)
@path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)
@path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)
@path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)
@path_array.each { |path| @queue << path }
@queue.delete(@cpath)
end
else
@queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)
@queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)
@queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)
@queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)
@list << @start
loop do
break if @queue.empty?
@cpath = @queue[0]
if @cpath.axis == @finish.axis
@finish.cost = @cpath.cost
@finish.from = @cpath
break
end
@list << @cpath
@path_array = []
p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])
p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])
p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])
p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])
@path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)
@path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)
@path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)
@path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)
@path_array.each { |path| @queue << path }
@queue.delete(@cpath)
end
end
if @finish.from.nil?
return nil
else
steps = [@finish.from]
loop do
cr = steps[-1]
if cr.cost == 1
@result = []
steps.each { |s| @result << Directions[s.dir]}
break
else
steps << cr.from
end
end
self.print_log(Time.now-st) if Log
return @result.reverse
end
end
def self.print_log(time)
print "\n--------------------\n"
print "Khas Pathfinder\n"
print "Time: #{time}\n"
print "Size: #{@result.size}\n"
print "--------------------\n"
end
end
 
Last edited by a moderator:

Ultim

Kartoffel.
Veteran
Joined
May 21, 2014
Messages
787
Reaction score
117
First Language
Arabic
Primarily Uses
Can anyone tell me how to dispose of a window using Event Script Calls ?
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
umm... what? lol

First of all, why are you displaying a (new?) window when an event is running?

Secondly, why do you have an event running when a window is opened?
 

As you may have noticed - these are the same question worded differently. I had to ensure I made the question as clear as possible. :)
 

Ultim

Kartoffel.
Veteran
Joined
May 21, 2014
Messages
787
Reaction score
117
First Language
Arabic
Primarily Uses
The window is already there when I run the event.Then,there's when I show the window using the vent.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
Why are you processing all the window methods within the event script call box then ?
Like, would it not be much easier to simply make one script call, that does everything you need.. - makes a window, makes it do what its doing, waits for a press or whatever, then closes ?

IMO - disposing of a window that the game is going to try and use as soon as its disposed is a very bad idea... (not sure if that is what you are trying to do exactly, but it sounds like it could be) :)
 

SoulPour777

Crownless King
Veteran
Joined
Aug 15, 2012
Messages
1,093
Reaction score
104
First Language
English
Primarily Uses
N/A
The window is already there when I run the event.Then,there's when I show the window using the vent.
Use the dispose method, or replicate the close method inside your window and call it on the event.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
What is the window? A message window? You can get rid of that without using a script call, just by adding a few escape codes to the window text (to tell it to pause long enough for the player to read the text, and then close automatically).


@seita, didn't I write a script for you not long ago that will maintain the same sprite over multiple event pages? If you want something like that to be permanent, it would be a new script, so I'd suggest you make a topic in RGSS3 Script Requests with more details (and a link to, or a copy of the script I wrote, if that is indeed what I'm thinking of)
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
I need to reorganize an array by moving valid entries to the front if there are no entries before them. What's the best algorithm for this?

I'm using a Variable as an array, with a capacity of 6 slots. Here's an example:

Var77 = [10, -1, 4, 9, -1, 6]

I need to move them around so that it becomes like this:

Var77 = [10, 4, 9, 6, -1, -1]

-1 would be an invalid entry, anything 0 and above are valid for our purposes.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
@seita

Code:
Var77 = [10,4,9,6,-1,-1].select {|i| i >= 0 }
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
At first I thought you wanted what Dekita provided, but I think you meant you want to keep the values, so here's my take to get what I think you want:

Code:
Var77 = [10, -1, 4, 9, -1, 6]Var77.each_index{|i| Var77.push(Var77.slice!(i)) if Var77[i] < 0}Var77 => [10, 4, 9, 6, -1, -1]
 
Last edited by a moderator:

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
@Dekita

Thanks for the quick response~ Initially I needed the -1's at the end still but that's given me a better result. Awesome stuff!

edit: @Galenmerth awesome, if I still need the -1's I'll try that out afterwards.
 
Last edited by a moderator:

Bastrophian

The Pixel Heartist!
Veteran
Joined
Oct 26, 2013
Messages
3,830
Reaction score
2,070
First Language
English
Primarily Uses
Other
Is it possible to make this script from yanfly support visual battlers on a sprite sheet separate from the default sprite sheet?....And also do separate animations for different kinds of actions. (i have an idea as to how i might achieve what im asking through eventing, like change the sprite sheets before every battle, but id rather not do that because it would be monstrously tedious, and i dont know how it might effect the game... :p )

EDIT: ...in vx ace  

https://github.com/Archeia/YEARepo/blob/master/Battle/Visual_Battlers.rb
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
for issues with specific scripts you should start a new thread in script support :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 5)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,479
Members
137,824
Latest member
dobratemporal
Top