ID:1614798
 
(See the best response by Multiverse7.)
Code: Vars
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?

It's an argument. It's likely short for damage. Arguments are variables you "pass" to the proc and they're used in it.

Example Call:
mob
verb/Attack()
var/mob/M = locate() in get_step(src, src.dir)
if(!isnull(M)) M.HurtMe(10) // If M exists, call HurtMe with D = 10
Best response
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:
////////////////////////////////////////////
// Below is the proc keyword. //
// Only procedures are defined within it. //
////////////////////////////////////////////
proc
/////////////////////////////////////////////////////////////
// Below is an example of a procedure definition. //
// //
// It consists of the proc's name followed by //
// the names of its arguments enclosed in parentheses //
// and separated by commas. //
// //
// Like variable names, procedure names and argument names //
// can only contain letters, numbers, and underscores. //
// //
// However, they cannot start with a number. //
// //
// An argument is like a special type of variable //
// used to input some type of data into a procedure. //
// //
// Like a variable, an argument //
// can be defined with a default value. //
// //
// The default value is only used if the arguments are //
// left blank in the procedure call. //
// //
// The only time arguments can be set //
// is when the procedure is first called. //
// //
// After that, the argument values become permanent //
// and last until the procedure has finished execution //
// and returns. //
// //
// Under that is the block of statements //
// that will be executed when the proc is used or called. //
// //
// All code is run or executed from left to right //
// and top to bottom. //
// //
// There are many different types of statements, such as //
// assignments, calls, returns, conditionals, and loops. //
// //
// In addition to statements, you can also //
// define variables that can be used within the procedure. //
// //
// Like arguments, these variables will be destroyed when //
// the procedure returns, but they may be freely modified //
// just like object variables. //
// //
// Procedure variables and statements are often combined //
// in complex assignments, but one must be careful //
// about where these are placed! //
/////////////////////////////////////////////////////////////
procedure_name(argument_name1, argument_name2, argument_name3, etc)
var
variable_name1 = "value1"
variable_name2 = "value2"
variable_name3 = "value3"
etc
// Evaluate and execute a statement.
// Evaluate and execute a second statement.
// Evaluate and execute a third statement.
// etc.


As for that code from the DM Guide:
mob
var/life = 100

proc/HurtMe(D)
life = life - D
if(life < 0)
view() << "[src] dies!"
del src

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.

var/life = 100 // Define a var named life under /mob with a value of 100.


proc/HurtMe(damage) // Define a proc named HurtMe under /mob, which can take an argument named damage.

if(!isnum(damage)) // If damage is not a number,

return // then stop execution here.

life -= damage // Subtract and remove the given value of damage from the value of life.

if(life <= 0) // If life falls to zero or below,

view() << "[src] dies!" // inform all other players in view that this mob has died,

del src // and delete this 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
var/vulnerable

verb/set_vulnerability(v as num)
vulnerable = v

HurtMe(N)
if(vulnerable)
..()
N is defined in the argument list.

Usually you code like this.
procName()
var/var1
var/var2

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)
var/var2
var/var3

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.