Help with Regexp

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
I put together this note tag.


/<Index:[ ](.*), Copy:[ ](.*), Take:[ ](.*)>/i


Usage1: <Index: 5, Copy: 3, Take: 2>


Usage2: <Index: 2, Copy: 2, Take: 0>


Usage3: <Index: 3, Copy: 1,2,3, Take: 3,2>


The method which evaluates this note tag works something like this. (Don't take it too literally)


def method(id, index, copy, take)
index = index.scan(/(.*)/)[0][0].split(",")
take = take.scan(/(.*)/ )[0][0].split(",")
copy = copy.scan(/(.*)/ )[0][0].split(",")
return if index.compact.delete_if(&:empty?).empty?
unless copy.compact.delete_if(&:empty?).empty?
copy.each do |id|
next unless id.to_i > 0
/something happens/
end
end
unless take.compact.delete_if(&:empty?).empty?
take.each do |id|
next unless id.to_i > 0
/something happens/
end
end
/some more stuff happens/
end # method




What I want to know is; how do I make the 'copy' and 'take' input values optional for the note tag without making separate notes (and methods consequently)?


Like this: <Index: 2, Copy: 3,4,5>


Or this: <Index: 3, Take: 1, 2>


So that copy remains as $2, and take as $3 either way.


This isn't a necessity, but it would be a nice feature.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top