[Ace] Getting a number and a string from a notetag

Joined
Jul 17, 2015
Messages
586
Reaction score
316
First Language
English
Primarily Uses
I'm trying to use notetags on equipped items to create a passive ability display, where the player can quickly see special effects granted by an equipped item in a window on the equip screen or in their status screen. (The notetag itself does not grant any effects on the actor; it is solely for the purpose of displaying special effects.) To see what I'm talking about, here is a mock-up I made of how the equipment screen would look:




The lower-left window displays the special effects of the respective equipment. Gee, I wonder what inspired this idea...



The notetag I decided to use for this is "<autoab: [number], [string]>", where the number is the icon number to be displayed and the string is a line of text to display. (So the first example on the mock-up would be something like: <autoab: 112, "Heal on Attack 1%">)


I've looked at several tutorials by RPG Maker scripters on notetags, but I cannot for the life of me figure out how to save the number and the string separately. (Which, to be frank, I don't blame the tutorials for in the slightest; I've learned everything I know through brute-force trial-and-error-emphasis-on-the-"error".) I'm fairly certain I'll be able to work out how to display the icon and string once I have the information, but how do I get the information from the notetag properly?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
That note-tag would look like this:


/<autoab: (\d+), (.*)>/i


This should give us 2 variables, the first would be the number (this: (\d+) ), and the second would be the string (this: (.*) ).


To access these variables, you can use $1 for the first and $2 for the second (and this could go on following the same logic if you would have more variables in your note-tag).


All variables extracted from regex are strings.


But since the first one should be an integer number and not a string, you should convert it by using $1.to_i.


Knowing the above, lets see an actual method for getting all the data we need the way we need it:


def autoability(item)
if item.note =~ /<autoab: (\d+), (.*)>/i
return [$1.to_i,$2]
end
end


Depending on where you want to use this, the method could look different. 


Since you use this only to draw the actual data on a window, you can place this method in the window class you are working in.


The item argument will be the checked item.


The method itself will check if the note-tag is present. If it is, it will return the data we need in an array, where the first element will be the icon index, and the second one will be the text. 


But if there is no such note-tag on the item, it won't return anything (well, it will return nil, which is basically nothing). For that reason, you should first check if the method returns something or not before doing something with it.


Lets see a complete method of drawing the data we get from the above method:


def draw_autoab(item,x,y,w,h)
if autoability(item) # Checking if the item got the note-tag or not
data = autoability(item) # Getting the data from the note-tag
draw_icon(data[0],x,y) # Drawing the icon from the note-tag
draw_text(x+24,y,w,h,data[1]) # Drawing the text from the note-tag
end
end


This would draw the data how you want at the designated co-ordinates in the window.


The x, y, w and h arguments are the X and Y positions and the width and height for the text respectively.


So, in short:


If you want to extract multiple data from a note-tag, you either use arrays, hashes or separate instance variables (the latter is really an overkill and should not be used).


Doing that will allow you to easily access the data, regardless of how many thing you got in the array/hash.


Ohh, and a last thing...


I noticed that you used quotation marks in your example note-tag for the text data. You don't need those marks there, because the entire note-box is a string.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
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.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top