Code:
main:{ // <=== This is function, it's name is "main".
if(level.server_announc_glob!=true){
level.server_announc_glob= true // <=== This is code RyBack send you on the top of "main" func.
}else{
end
}
while(1){
wait 15 // Tells script to wait given time in seconds.
stuffsrv("say Welcome to the server") // console msg.
wait 10
iprintln("Welcome to the server") // the yellow game message which shows below the compass.
wait 10
iprintlnbold("Welcome to the server") // the white game message which shows below the compass.
wait45
}
}end
In simple words, function in programming is named part of a program which have to perform specific actions. It's good if you keep your functions small and it's good if one function have only one task to perform. In morpheus(MOHAA scripting language) functions usually begin like that:
Code:
my_awesome_function:{
}end
but more often I see:
my_awesome_function:
end
Functions usually end with "end" statement which tells, obviously, that this is end of function named my_awesome_function. It's worth mentioning that you can call function inside other function, it will help you later if you will take up modifying your own server and scripts or if you would like to understand what the hell someone is doing in his code.
Code:
main:{ // <=== This is function, it's name is "main".
if(level.server_announc_glob!=true){
level.server_announc_glob= true // <=== This is code RyBack send you on the top of "main" func.
}else{
end
}
thread my_awesome_function //<====== Calling function my_awesome_function.
}end
my_awesome_function:{
while(1){
wait 15 // Tells script to wait given time in seconds.
stuffsrv("say Welcome to the server") // console msg.
wait 10
iprintln("Welcome to the server") // the yellow game message which below the compass.
wait 10
iprintlnbold("Welcome to the server") // the white game message which below the compass.
wait45
}
}end
Function named my_awesome_function contains now code which is responsible for generating MOTD messages as a console or text under compass, but it's not used anywhere, game doesn't know what to do with it, so we have just unused set of instructions. To start using it we can call this function inside "main" function, by typing: thread
functionname. And now this code will do exact same thing like in first []code brackets. Sorry if I'm explaining it to you in a bit chaotic maneer, I'm still sleepy. :P
With the same logic you can call functions even from other scripts:
Code:
exec folderwherefileis/filename.scr::functionname