Jan 9 2016, 9:20 am
|
|
Ok cool and in case I really need to use loop for something what is the proper way to use it if you don't need to use goto?
|
Ok cool and in case I really need to use loop for something what is the proper way to use it if you don't need to use goto? It depends on the situation. There are several different types of loops that all do something slightly different. Let's say you need to loop through a list of items without responding to changes the list: for(var/obj/item/i in l) If you need to loop through a list of items while changing the list: for(var/count=1;count<=l.len;count++) If you need to loop through every other item in a list: for(var/count in 1 to l.len step 2) If you need to count backwards through a list: var/pos = l.len+1 If you need to do something with a guaranteed first-iteration: do There's no one right way to loop through a list. It depends on what the loop is trying to achieve and it comes down to logic. You have to think about the problem you are teaching the machine to solve, and then apply the simplest solution possible within the constraints of the machine's purpose. If you don't understand the theory of what each piece of logic does, and all of the tools at your disposal, you are going to have a hard time finding a good solution. This is why it's really best to read the materials that are provided to you before you dive right in, just so you are at least aware of what's available to you. http://www.byond.com/docs/guide/ http://www.byond.com/docs/ref/index.html I didn't read these when I first started out. I still haven't read them all the way through, to be honest, and it took me 13 years to really understand programming well. You can master it in 1-3 years if you start right. Otherwise, you are going to spend a lot of time making mistakes that could have been prevented. The reference is something you don't want to read all the way through. it's something that you want to sort of peruse through after you've got the basics down, and just sort of read stuff that piques your interest. When you are trying to solve a specific problem, it's really quite helpful to search through it to figure out how things work. The guide, on the other hand is a good lazy sunday afternoon read. |
I tried to tweak your code for my needed but see what it did:
http://img11.hostingpics.net/pics/942630examinfos.png //in my var(global var) |
var These lines are invalid. get rid of them. You also should never use stat() outside of mob.Stat() or a proc called by mob/Stat(). next_genin_exam = world.realtime + 18000 These lines are wrong too. You can't set global variables like this. |
This is closer to what you need to do:
var |
the stat() were already into Stat() (finally something I know :P) but didnt know I should of put the variables in a process because it had equation thank you for the specification!
|
and I had already put check_exams in world/New() finally another thing I knew xD (A great thank you to know idk if you find me annoying but you're really helping me thank you)
|
idk if you find me annoying Not at all. We all start somewhere. Trust me, you are nowhere near as bad as I was when I first started out. I was an absolute menace back in 2001. =D I'm just very, very blunt, so it might seem like I'm always annoyed, but it's just sort of how I talk/think. I can come across very aggressive in text, but if you could hear my voice, I'm sure you'd figure out that I'm more than happy to help. Cheers. |
idk what went wrong this time: http://img15.hostingpics.net/pics/980987exam.png
world |
Pay close attention to my world/New() function. You implemented it incorrectly.
|
This part?:
New() |
Yes that's what I was thinking I wrote it too fast! I like the way you told me asking me to try to wonder why and not just telling me what is wrong :D!
|
still same error as the other screenshot D:
next_genin_exam = world.realtime + 18000 |
There are one of two possibilities. Either world/New() is never being called because you have it overridden somewhere else in your project (you didn't start fresh, like you said), or you are subtracting world.realtime in the wrong order in your Stat() proc.
You can check if a proc is being called by inserting a debug message into it:
world.log << "Put your debug message here"
And when the world starts, press F1 to open the options and messages menu to see if that message was sent. You can also check to see why values are out of whack by using debug messages: world.log << "[world.realtime] [next_genin_exam]" My guess is that one or both of these things is wrong, and you need to double-check your mob/Stat() function to make sure you are subtracting the values in the right order, like I showed you above, and you need to make sure that world/New() is actually being called and not being incorrectly overridden elsewhere in your code. |
here's the stat() if tyou want to see it:
var/time = world.realtime |
My guess is that you are accidentally overriding world/New() multiple times and not using the supercall operator.
This will tell you a bit about what the supercall is, and how overrides work: http://www.byond.com/forum/?post=2008907#comment17929110 |