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

[制作教程] Intermediate/Advanced Game Variables

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

    连续签到: 2 天

    [LV.7]常住居民III

    4446

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 前天 10:10 | 显示全部楼层 |阅读模式
    Intermediate/Advanced Game Variables

     
    Variables are useful in the creation of complex eventing systems that add functionality to any RPG Maker game. Once you get the hang of using them, they become an integral part of the game development process. However, once you start digging deeper into the system and use variables in conjunction with script calls, you'll find that they're magnitudes more useful than you previously thought. First things first. Before tackling this tutorial, make sure you are well versed in basic variable manipulation. Here are some recommended tutorials or skills needed that can help you catch up:

     ​

    Show me something new about variables.

     
     
    To you scripters out there, this isn't news and this is just basic programming. Alright so most people use variables as to deal with numbers. Bank accounts, how much of an item the player has, map coordinates, health manipulation and so forth. What a lot of people don't realize is that you can put almost "anything" into a variable. That includes letters, words or sentences (or strings). Why would you want to do this? A simple example of using variables for non-mathematical reasons would be a password system. There's already a basic tutorial of this on the RMW blog:

    This is all well and good, but what if you want it to be very specific? Maybe the player has to make up a password early on in your game, and use it again later on. Maybe you want a password that uses multiple elements of the game, like a characters name with his level right afterwards, for some reason. Let's tackle the first one:
     

    Create and Enter a Password.





     
    With Event 6, we've created an Actor with the ID of 5 and named him Password for our purposes, and used this actor for our password input. Then we transfer "Passwords" new name into Variable 1.
    With Event 7, we first empty Actor 5's name with the script call: $game_actors[5].name = "". By using two quotes, we've essentially emptied his name. If you skip this step, the actors name (or this case, our password) will show up in the name field. No fun, cheater!
    Afterwards we use the same actor for the password input and then check it by comparing it to the first password we stored in Variable 1. Using == means we are checking if the value on the left is the same as the one on the right.
    Keep in mind, the password must be EXACTLY the same as when you first input it. That means "Password" is not the same as "password".
     

    Variables in Variables...?

    Now lets get into something more complicated. Did you know that a variable is made up of an uncountable number of variables in it? That means you can have more than 5,000 variables without a script. In theory you could have way more than two billion variables! We call this an Array. So how do we take advantage of this? Lets look at how we can do this:
     




     
    As you can see here, using the script call $game_variables[9] = is the same as using the event command Control Variables. Here's the syntax on how to make a variable into an array, and how to access parts of this array.
     




     
    In order to make a variable into an array, we have to tell the game. We do this by initializing the variable with a data set within brackets, separated by commas: $game_variables[8] = [5, 10, 24, 4000].
    In our example, I set variables 9 to 13 as separate entries of the array we made from variable 8. We access these entries by using the Index following $game_variables[#]. Realize that the first entry starts at 0, and increments up. So the first entry "5" is accessed by $game_variables[8][0].
    The reason we are using Variables 9 through 13 to show the values within the array is because there is no window command that allows us to access these values. The easiest way to go about this is to have a number of variables be temporary use variables specifically for this purpose. Any scripter want to rectify this by adding some message box functionality?
    You'll also notice that Variable 13 which accesses the 5th item (indexed as 4, because the 1st item is indexed as 0) is Zero. This is because all variables including any uninitialized entry within the array starts as Zero, also known as Nil. (for comparison, Switches are called "bools" and can only have two values, 1 and 0. 1 is On, and 0 is Off.)
     
    Warning: If you use a normal Control Variable command on an array, it will overwrite the whole array with whatever you do in the command.
     
    To really take advantage of arrays, you have to be fairly proficient with Script Calls. Going through the Script Call Equivalent of Events topic will really help. In here, you'll be able to find or ask for any equivalent of the Event Command Window as a script call. The following image shows all of the script call equivalents of the Control Variable command.
     




     
    As you can see, the equivalents are pretty identical except for how it shows the variables themselves. In fact, if we just wanted to see "exactly" what was in the array without adding the separations to make them look similar, all we would need to do is use \V[8] in the command window.
     





    Using Strings (letters, words, statements).

     
    Lets make things a little more interesting. How about I show you what we can do with strings instead? Did you know we can add strings together? What it does is append the second string onto the first. This is called concatenation. Here's an example.
     




     
    Here, array 10 entries 0, 1 and 2 are "My", "name", and "no". We initialize variable 11 with entries in array 10 and add spaces and other words to create a whole sentence.
     




     
    Now we've done something more useful with these variables. Did you know that a variable that's initialized as a single string is basically an array of letters (chars)? If you look at the code we can get single letters out of a string, or a name of an actor within the game. Perhaps you have the player input a name but you want someone to say it differently. Maybe they stutter or are short of breath.
     
    First we initialize variable 11 with the party leaders name. Perhaps the party leader is the first person the event character sees. We then create a 'sentence' with variable 13 by adding specific portions of variable 11 (the name) and other things such as dots, question marks and so forth. We can do the same with a specific actors name, in this instance, Eric, the first actor. Don't want the event to say the same name twice if the leader and actor 1 are the same? How about doing a conditional. if $game_variables[11] == $game_variables[13] then use a different actor if its the same!
     
    What about that super special password?
     




     
    Easy peasy! All we did here was use three temporary variables. We initialized variable 11 with the leaders name, and 12 with the amount of gold. By using to_str() we've told the game to convert the numbers to string so that it can add it to the sentence. Without doing this, the game would give us an error, so it's very important!. After this, we initialize variable 13 with the first two letters of variable 11 by getting the index of the first two letters, in positions 0 and 1. Then we simply add the gold we've made into a string, and there we have it! Once the player inputs the password, we compare it to variable 13 and see if its correct. We then use another temporary variable 14 to show them the answer they have input. Edit: Actually, I could have just used \V[13] since it's assumed to be correct in that conditional...

    So I've explained how to go about using variables in different ways. There are much more creative people out there than me, and these techniques serve to bolster your repertoire in eventing. Have fun with it! It adds a whole new level of polish to a game that otherwise may be too straight forward. If I missed anything or something is too vague, please post and I'll gladly add to the tutorial. Have fun!


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-14 14:21 , Processed in 0.063859 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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