官术网_书友最值得收藏!

Using a method in a script

Methods are where the action is and where the tasks are performed. Great, that's really nice to know but what is a method?

What is a method?

When we write a script, we are making lines of code that the computer is going to execute, one line at a time. As we write our code, there will be things we want our game to execute more than once. For example, we can write a code that adds two numbers. Suppose our game needs to add the two numbers together a hundred different times during the game. So you say, "Wow, I have to write the same code a hundred times that adds two numbers together. There has to be a better way."

Let a method take away your typing pain. You just have to write the code to add two numbers once, and then give this chunk of code a name, such as AddTwoNumbers(). Now, every time our game needs to add two numbers, don't write the code over and over, just call the AddTwoNumbers() method.

主站蜘蛛池模板: 内黄县| 察隅县| 南郑县| 赣州市| 南乐县| 长治县| 延川县| 建昌县| 黄梅县| 当雄县| 休宁县| 拉孜县| 雅安市| 元江| 西平县| 横山县| 巍山| 乌兰浩特市| 洮南市| 巴南区| 高雄县| 武义县| 曲阜市| 临泽县| 兴宁市| 榆中县| 噶尔县| 城步| 天台县| 栾城县| 吉林省| 贵州省| 正安县| 白银市| 类乌齐县| 新龙县| 醴陵市| 凤冈县| 县级市| 永兴县| 颍上县|