设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 150|回复: 0

[制作教程] A Guide to Notetagging

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-7-12 08:46:23 | 显示全部楼层 |阅读模式
    Can also be read on my blog: http://cobbtocs.co.uk/wp/?p=312

    So you’re getting into scripting, maybe you just released a script and naturally you’re a bit peeved because the first person to reply did nothing but complain about the lack of note tagging, maybe the second reply agreed with him… Right so now you’re a double murderer but want to learn how to incorporate note tagging in your future scripts. Then this tutorial is for you.

    First let me begin by saying note tagging is NOT REQUIRED NOR EVER WILL BE for a script. It does not improve a script, it does not in any way make a script better. It only makes a script easier to use for people of no scripting ability or those with a weak disposition about editing a script. In some ways it’s a bad thing because it encourages a plug and play attitude and keeps people from doing minor amounts of scripting (which can lead to a better understanding of scripts). But clearly if you’re reading this then you want to make your scripts more “user friendly.” So let’s have a look at the potential classes you can use note tagging in:





    Hopefully you will be able to find in the database and editor where you put the notetags. Notetags usually look like:



                    Code:        
    1. <notetag x>
    复制代码

    I don’t know who came up with the format but it effectively mimics html tags, notetags don’t have to look like that but it’s what people are used to. If you do something different then any “user friendliness” you add to your script will be quickly be diluted with queries and uncertainty about the notetagging.

    Right let’s now get into the code, hypothetical scenario you have a script where by one of your characters has a chance to not consume an item when using it and you want each item to have a different chance to avoid been consumed. You’ve decided your notetag will be:



                    Code:        
    1. <con x>
    复制代码

    A quick look at the diagram I’ve provided you should lead you to: RPG::Item. Different people implement notetags in slightly different ways, for example Yanfly built an entire architecture around pre-loading notetags but I’ll just show you the way I do notetags and if you’re interested in other ways of notetagging you can also go look at how other scripters implement it.

    So we’ve got our class, RPG::Item let’s go into them the script then:



                    Code:        
    1. class RPG::Item
    2. end
    复制代码

    We now need to add the new method you’ll call from somewhere in your script.



                    Code:        
    1. class RPG::Item
    2.   def conserve_chance
    3.   end
    4. end
    复制代码

    In all the classes with notes the note is stored in a variable called @note. Anyway this is what our final code looks like:



                    Code:        
    1. class RPG::Item
    2.   def conserve_chance
    3.         if @note =~ /<con (.*)>/i
    4.           return $1.to_i
    5.         else
    6.           return 0 # the default if no notetag is present
    7.         end
    8.   end
    9. end
    复制代码

    Let’s just examine it a bit closer. =~ basically is checking for a match with the notetag. The two / are to do with regex which unless you want to look into more closely then what I go through here should see you through setting up any note tag. As for .* the . accepts any character except line breaks and the * means you can enter as many as you like. Finally the i after the second / just tells it to ignore case meaning <con x>, <CON x>, <Con x>, <CoN x> would all be accepted as a match.

    $1 effectively holds whatever was placed in the notetag, by default it will be a string, if you need it to be an integer then add .to_i onto it like in the example.

    I think that concludes the main chunk of the tutorial but there are two more things I want to go through getting an array from notetagging and inheritence with notetagging.

    Lets jump into getting an array from notetagging, $1 contains the string from the notetag so we could have people enter the array like: <array 1,2,3,9,4> for example. There is a highly useful function in ruby called split and what it does it break up a string and return an array, best part of all if we can tell it how to break the string up. Right below are two examples one for an array of string and one for an array of integers.



                    Code:        
    1. class RPG::Item
    2.   def conserve_chance
    3.         if @note =~ /<con (.*)>/i
    4.           return $1.split(",")
    5.         else
    6.           return []
    7.         end
    8.   end
    9. end
    复制代码




                    Code:        
    1. class RPG::Item
    2.   def conserve_chance
    3.         if @note =~ /<con (.*)>/i
    4.           ints = []
    5.           for x in $1.split(",")
    6.                 ints.push(x.to_i)
    7.           end
    8.           return ints
    9.         else
    10.           return []
    11.         end
    12.   end
    13. end
    复制代码

    Right then that just leaves me to go through inheritance and notetags. If I may draw your attention to subset of the diagram above:





    What the arrows represent is inheritance (I know that in UML they should be clear arrowheads but I don’t care). Inheritance is where the classes inherit all the variables and methods from the other class. The variable note exists in the RPG::BaseItem class and them all the other classes in the diagram inherit it. What this means is that if you need the same method in more than one of these classes you can put it in a class which the classes you need the method in inherit. So for example if I want to add something to both Weapons and Armours then I can put the method in EquipItem.

    So hopefully this has helped you understand how to incorporate note tagging in your scripts, if you’re desperate to use notetagging when there are no notes you could always consider name tagging! But in all seriousness if you need any further help or clarification please don’t hesitate to leave a comment.

    Jet has scolded me for performing the check every time the method is called so here’s an example of how to cache the notetag so that it only calculates it once per session.



                    Code:        
    1. class RPG::Item
    2.   def conserve_chance
    3.         if @conserve_chance.nil?
    4.           if @note =~ /<con (.*)>/i
    5.                 @conserve_chance = $1.to_i
    6.           else
    7.                 @conserve_chance = 0
    8.           end
    9.         end
    10.         @conserve_chance
    11.   end
    12. end
    复制代码




    本贴来自国际rpgmaker官方论坛作者:Fomar0153处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/a-guide-to-notetagging.1686/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 11:02 , Processed in 0.077433 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表