ID:1500294   Feb 18 2014, 2:41 am (See the best response by Makeii.) Code: ```mob icon= 'Male.dmi' verb Dex() dexxp = dexxp+ rand(1,20) usr << "[dexxp]/[dexmxp]" var dex= 10 dexxp= 0 dexmxp= 100 proc LevelCheck() if (dexxp >= dexmxp) src.dexxp = 0 src.dexmxp= dexmxp * (((rand(0,10))/25)+1) src.dex= dex + rand(1,2) return ``` Problem description: Well, I know, I know, I should check out articles about how procs work, however, I already have. I simply cannot understand most of it. In the code above, I do not know how to make it constantly check for experience surpassing max experience, thus leveling up.
 Feb 18 2014, 4:06 am /mob/verb/Dex() gives exp, so just call LevelCheck() from there.
 Feb 18 2014, 4:30 am (Edited on Feb 18 2014, 6:14 am) You don't need your game to constantly check. You only need to it to check when the person receives some amount of XP. Zaoshi already said this in words, but I think showing you may help you understand. (Look for the commented code) ```mob icon= 'Male.dmi' verb Dex() dexxp = dexxp+ rand(1,20) usr << "[dexxp]/[dexmxp]" LevelCheck() //This will call the LevelCheck() proc that is defined below var dex= 10 dexxp= 0 dexmxp= 100 proc LevelCheck() if (dexxp >= dexmxp) src.dexxp = 0 src.dexmxp= dexmxp * (((rand(0,10))/25)+1) src.dex= dex + rand(1,2) //return : commented this line out as it was incorrect (thanks ssj4) LevelCheck() //this will call itself, effectively creating an infinite loop. You don't want this... ``` So, now that you've seen how you can call a procedure, you just have to figure out when you want it called. As Zaoshi said, a good idea would be to have it called from within Dex(). That way you only call it when there is a reason to check for a level increase. I'd highly recommend reading up from documentation within dream maker about arguments as well since you're learning about procedures. The more you read and practice what is in there, the more nifty ways you'll learn how to accomplish things. *edit for TL;DR* Don't copy and paste. This code snippet was made to show you how things CAN be done, not to show you the best way. The "best" was told to you, and you'll have to apply this knowledge on your own ;)
 Feb 18 2014, 4:36 am In response to Koshigia Best response Koshigia wrote: You don't need your game to constantly check. You only need to it to check when the person receives some amount of XP. Zaoshi already said this in words, but I think showing you may help you understand. (Look for the commented code) ```> mob> icon= 'Male.dmi'> verb> Dex()> dexxp = dexxp+ rand(1,20)> usr << "[dexxp]/[dexmxp]"> LevelCheck() //This will call the LevelCheck() proc that is defined below>>> var> dex= 10> dexxp= 0> dexmxp= 100>> proc>> LevelCheck()> if (dexxp >= dexmxp)> src.dexxp = 0> src.dexmxp= dexmxp * (((rand(0,10))/25)+1)> src.dex= dex + rand(1,2)> return>> LevelCheck() //this will call itself, effectively creating an infinite loop. You don't want this...>> ``` So, now that you've seen how you can call a procedure, you just have to figure out when you want it called. As Zaoshi said, a good idea would be to have it called from within Dex(). That way you only call it when there is a reason to check for a level increase. I'd highly recommend reading up from documentation within dream maker about arguments as well since you're learning about procedures. The more you read and practice what is in there, the more nifty ways you'll learn how to accomplish things. I would personally prefer to do the LEvelCheck() code non-recursively. ```mob/proc/LevelCheck() while (dexxp >= dexmp) // will never run otherwise dexxp -= dexmp // in case of overflow (i.e. dexxp = 102 / 100) dexmp *= (rand(0,10)/25) + 1 dex += rand(1,2) ```
 Feb 18 2014, 4:41 am In response to Makeii Yeah, as much was said in other words already. I alluded to that twice in one post, as a matter of fact; Once in the very first statement, and once in the comment for the recursively called procedure in the code snippet.
 Feb 18 2014, 6:03 am In response to Koshigia Koshigia wrote: You don't need your game to constantly check. You only need to it to check when the person receives some amount of XP. Zaoshi already said this in words, but I think showing you may help you understand. (Look for the commented code) ```> mob> icon= 'Male.dmi'> verb> Dex()> dexxp = dexxp+ rand(1,20)> usr << "[dexxp]/[dexmxp]"> LevelCheck() //This will call the LevelCheck() proc that is defined below>>> var> dex= 10> dexxp= 0> dexmxp= 100>> proc>> LevelCheck()> if (dexxp >= dexmxp)> src.dexxp = 0> src.dexmxp= dexmxp * (((rand(0,10))/25)+1)> src.dex= dex + rand(1,2)> return>> LevelCheck() //this will call itself, effectively creating an infinite loop. You don't want this...>> ``` So, now that you've seen how you can call a procedure, you just have to figure out when you want it called. As Zaoshi said, a good idea would be to have it called from within Dex(). That way you only call it when there is a reason to check for a level increase. I'd highly recommend reading up from documentation within dream maker about arguments as well since you're learning about procedures. The more you read and practice what is in there, the more nifty ways you'll learn how to accomplish things. *edit for TL;DR* Don't copy and paste. This code snippet was made to show you how things CAN be done, not to show you the best way. The "best" was told to you, and you'll have to apply this knowledge on your own ;) This is a good example except for the part when you state that it will call as an infinite loop. If you take a look at your code, you have ```LevelCheck() if (dexxp >= dexmxp) src.dexxp = 0 src.dexmxp= dexmxp * (((rand(0,10))/25)+1) src.dex= dex + rand(1,2) return LevelCheck() //this will call itself, effectively creating an infinite loop. You don't want this... ``` Return called before LevelCheck(), thus making only one cycle.
 Feb 18 2014, 6:14 am In response to Ssj4justdale Ah, good catch :) Corrected it and credited you, SSJ
 Feb 18 2014, 7:25 am In response to Koshigia No need for credits, just bored and like to help people in my spare time :)
 Feb 18 2014, 7:34 am In response to Ssj4justdale Yeah, I'm the same way. I've never been much of a forum-goer since I joined BYOND in 2001, but I like this forum in particular as it helps me improve myself as well, and occasionally gets me to read some interesting information that I may not have stumbled upon otherwise. I also really enjoy reading the in-depth replies from some of the ones more familiar with assembly, BYOND, compilers, etc.
 Feb 18 2014, 7:41 am In response to Koshigia Yeah I enjoy technology and whats behind it as well :)
 Feb 18 2014, 7:55 am Zaoshi wrote: /mob/verb/Dex() gives exp, so just call LevelCheck() from there. More than just calling it in Dex(), it is pretty common to handle changes in a AddExperience() procedure. The reason behind this is that there are many ways that Experience can be added in a common game. Some include Party Experience, Monster Killing Experience, Quest Experience. Now, you'll be writing code to provide Experience, and each time you'll be expected to handle certain events (Level Up, Updating Huds, etc) so placing these events in a procedure to encapsulate that behavior is a pretty good idea. Down the road, if you decide to add an item that increases Experience Gained, then you'll only have change one area of code.
 Feb 18 2014, 11:37 am Thank you. This really helped me, not only in the specific proc, but it also helped me understand the applications of proc in general.