ID:179966
Sep 29 2001, 10:01 am
|
|
I have come across a nasty bug in my game. In my game, you are able to build cities. But I have seen that people can build cities on top of other cities. Is there a way to check to see if there is another city at a location before you can build one there?
|
In response to Spuzzum
|
|
Thank you again Spuzzum. But I would like to ask if you could explain how the Break proc works as I am taking down notes. I would like to know how it operates :-D
|
In response to Deadlocke
|
|
Deadlocke wrote:
Thank you again Spuzzum. But I would like to ask if you could explain how the Break proc works as I am taking down notes. I would like to know how it operates :-D The break proc (it's technically a statement, but BYOND refers to everything as procs =) will terminate execution of a certain block of code (only certain code sections are accepted). However, this can be used to your advantage. Whenever for() loops through objects, it sets the variable equal to the object it is looking for. eg. for(var/obj/O in world) After the loop is finished, O is set back to null. But, if you abruptly halt the for loop; var/obj/O O will not be reset to null because for() will not have finished executing. Thus, O will contain the very first object of that type found. Note that the following: for(var/obj/O in world) is useless, because the variable "O" only belongs to that block of code. If you tried the following: for(var/obj/O in world) you would get bad var errors for "O". These are the types of code sections you can use "break" with. while() do...while() for() list (for(var/obj/O in world)) for() loop (for(x = 1, x <= 20, x++)) |
In response to Deadlocke
|
|
A strategy:
Look in the F1 help in Dream Maker. I did it before I even looked ahead and saw your request or spuzzum's answer. This is what F1 told me: break proc That told me just how to use the break proc. Good luck! |
In response to Deadlocke
|
|
Another thing worth mentioning (which you may have deduced on your own or not) is that by "typing" the variable O, you can specify only a particular type of object to look for.
For instance: var/O for (O in...) will look for anything and everything in the turf. var/obj/O for (O in...) will only look for objs. var/obj/city/O for (O in...) will only look for cities. |
Yup!
mob/verb/look_in_location(turf/T)
var/obj/O
for(O in loc) break //now O will contain whatever was there.
if(O)
usr << "There is an [O] there."
else
usr << "That space is empty."