mob
var/life = 100
proc/HurtMe(D)
life = life - D
if(life < 0)
view() << "[src] dies!"
del src
Problem description: In the reference under chapter 6 "D" is placed inside parenthesizes, why? What is it's significance of being there?
Code: Vars
mob Problem description: In the reference under chapter 6 "D" is placed inside parenthesizes, why? What is it's significance of being there? |
Alex Ovide wrote:
Problem description: In the reference under chapter 6 "D" is placed inside parenthesizes, why? What is it's significance of being there? Did you keep reading after that point? It gives you some examples of how that procedure could be used, which might help you understand it. This is one of the first things you learn about when you start to learn your first programming language, and I can understand if the DM Guide isn't good at explaining it. What you need to learn are the true basics of the procedural programming syntax and structure. Here is a basic outline: //////////////////////////////////////////// As for that code from the DM Guide: mob It's not a good example for absolute beginners. Let me try to clarify it, and break it down for you: mob // Definition for the type /mob. So, to call this proc you would just write something like mob_to_hurt.HurtMe(10). Since this a procedure we defined and not one that is built-in, we could also set the argument directly, using its name, instead of its placement, just like we would with a variable: mob_to_hurt.HurtMe(damage = 10). As you should now know, procedures are complex on the inside, but simple on the outside, which is what allows us to write amazing programs that we could never comprehend the workings of all at once. That can be either a good thing or a bad thing. You just have to know how to manage the complexity and keep things modular, in order to be successful. |
Thank you so much that help a lot, my confusion now is "D", does it have to be defined so where else as a var in the game so the process can relate to it?
or Is "D" already defined in the process and acts as a temp? I read past the chapter and I guess having no experience in code made me overlook the given explanation. Yours actually help. |
So this case what the hell is "N" it's not defined any where
mob/DM |
N is defined in the argument list.
Usually you code like this. procName() in which case the variables for the entire scope of the proc are var1 and var2. But arguments are also variables that you can use throughout the entire scope of the proc. procName(var/var1) Has 3 variables you can use throughout the entire scope of the proc. An important thing to be wary of is when you're using arguments in your procs, to remember to actually pass the argument because if you don't (and you don't have a default value), then you're gonna get run-time errors. |
Example Call: