I tried to make simple event loop, but all i found browsing - Deadron's event loop, which includes libs. Without libs, how to make a loop?
Jan 6 2016, 6:06 am
|
|
What are you trying to do?
|
Can you be more specific? What's the use-case? When should it operate? How often should it operate? Is it looking for all mobs? What object is doing the looking?
|
I have an object. What is my goal - to make him check range 5x5 tiles for any mob. How to do the check - i know, probably. But how to make tick, which run proc every couple of seconds without libs - i have no idea.
|
obj/someobj You'll want to look up while loops, do while loops, and for loops. Those are the three basic kinds of loops. You should note that this approach is probably better not done at all. Manually polling for objects nearby is incredibly inefficient, and there are much better ways of doing this without looping. For instance: trigger_area The above object is a way to persistently detect objects that cross over a certain part of the map that's defined by the bounding area of this object. These should be stationary. If the detection area needs to be moved, this solution will not work for you. It's just faster to poll if the object needs to move. You can use them like this: obj This approach requires no constant looping to check for interlopers. |
Ter's solution is good advice in any similar case, too. Like for instance if you have a field full of monsters, you really don't want to trigger their AI loops till they're actually in range of anyone, or else you're wasting CPU cycles.
|
you really don't want to trigger their AI loops till they're actually in range of anyone It should really be stressed here, though, that my trigger_area solution only works reasonably for stationary objects. Because of the overhead of moving around objects with large bounding boxes, you really don't want a large number of these guys flitting around the map all the time. For something like AI, it's usually best to develop some kind of a chunk/observer approach that keeps track of what clients are and aren't near. Unfortunately, this is a topic that even someone as well-versed as I am hates dealing with. |