En Çok Reaksiyon Alan Mesajlar
Thanks for release, the idea isn't bad, but there're some bad things.
I'll show you the problems part and how can be improved, there're just advices, i hope you'll get them.
Python:def __del__(self): if len(self.eventList) > 0: self.eventList.clear()
If you're using Python 2+ or Python 3.2 and below, you can't use the clear() method (allowed on 3.3+), also as i said in the second message you don't need to check the length of the list, already the clear() method doing that inside and there's no reason to put it to __del__ method, it will be called when the object is garbage collected. if you really want to use in future, something outside of this and want just to check the list if isn't empty, is enough to do it just with if some_list, like a normal boolean, there no need to check the length of the list if you don't use it in your code.
You don't have to check the list if you already did a numeric range loop or iterator based loop.Python:if len(self.eventList) > 0: for j in xrange(len(self.eventList)): [...]
Python:self.eventList = [] ''' example 1 ''' for i in xrange(len(self.eventList)): print (self.eventList[i]) ''' example 2 ''' for event in self.eventList: print (event) #<nothing will be printed>
I would say to use app.GetGlobalTimeStamp() instead of app.GetTime(), if you teleport while the event is running, the event function will run after 10 seconds like. While app.GetGlobalTimeStamp() will run after the specific time, because is the server timestamp and is updated on each enter in game.Python:app.GetTime() + time
I would put here an big exclamation, with this you creating 999999999 lines in syserr, what you do here is like:Python:if i == 0: self.eventList[j].clear()
While Process() function is called in OnUpdate, so, your condition trying to get the returned value from an specific function, what means the next update time or 0 to destroy the event/clear it. Everything's fine until you return 0 and event should be stopped yes? But there is a problem, you clear the specific dictionary of event and still remained in the list [{}], and the Process() function will take your self.eventList with the items included, the empty dictionaries from your events, and of course even if you've [{}, {}, {}], that doesn't mean your list is empty, have 3 items, so, the loop will trying to read an empty dictionary and you'll get key errors in each milisecond. The method which you need is to delete the dictionary itself from the list after the result value from the function is 0, like this:
[/SPOILER]Python:del self.eventList[j]
_______________________________________
I wrote fast some self extensions, if somebody is interested i'll do another updates in the next days.
You can use unlimited arguments on functions, now is using the apply method which returns the result of a function or class object called with supplied arguments, with the old structure you could use just one argument.
You can lock/unlock an event for being processed, it's like a prevent in some actions, if the event is created and you want to do something, you should lock the event, do some actions then you can unlock it again and the process function will run where remained.
Delete an event instantly and force it to stop the process.
Adding return t.EXIT inside of the running function, will delete the event too.
Functions to check if an event exists or is locked or not.
Check if the function is a Öğeyi görmek için üye olmalısınız..
Delete the events with a properly method.
Using app.GetGlobalTimeStamp() now will give you the chance to run the event after teleport where timer remained instantly.
[/SPOILER]Python:t = ui.Queue() # ex1 t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run) # ex2 t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run, eventFuncArgs=player.GetLevel()) # ex3 t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run, eventFuncArgs=(player.GetLevel(), player.GetName())) # ex4 t.AppendEvent('UPDATE', 0, self.Update, {'data' : (1, True, (14, 12), [5, 1], 'Corsair')}) # Others: if t.GetEvent('RUN'): print ("The event exists.") if t.GetIsLockedEvent('RUN'): print ("The event exists but is locked.") t.LockEvent('RUN') t.UnlockEvent('RUN') t.DeleteEvent('RUN')
_______________________________________
The code:
Python:class Queue(object): EXIT = 0 def __init__(self): self.eventList = [] self.eventLockedList = [] def __del__(self): del self.eventList del self.eventLockedList def GetEvent(self, eventName): """ Get the event dictionary by specific name. """ for event in self.eventList: if event['name'] == eventName: return event return None def GetIsLockedEvent(self, eventName): """ Get a boolean if a specific event is locked. """ for event in self.eventLockedList: if event['name'] == eventName: return True return False def LockEvent(self, eventName): """ Lock a specific event by name for being processed. """ event = self.GetEvent(eventName) if event and not event in self.eventLockedList: self.eventLockedList.append(event) def UnlockEvent(self, eventName): """ Unlock a specific event by name for being processed. """ event = self.GetEvent(eventName) if event in self.eventLockedList: self.eventLockedList.remove(event) def DeleteEvent(self, eventName): """ Delete a specific event by name instantly. """ event = self.GetEvent(eventName) if event: self.eventList.remove(event) def ResetTimeEvent(self, eventName): """ Reset time of a specific event by name. """ event = self.GetEvent(eventName) if event: index = self.eventList.index(event) self.eventList[index] = app.GetGlobalTimeStamp() def AppendEvent(self, eventName, eventStartTime, eventFunc, eventFuncArgs = ()): """ Append a new event by specific arguments. """ if not eventName or not isinstance(eventStartTime, int) or not callable(eventFunc): return if not hasattr(type(eventFuncArgs), '__iter__'): eventFuncArgs = tuple([eventFuncArgs]) if self.GetEvent(eventName): self.DeleteEvent(eventName) self.eventList.append({'name' : eventName, 'function' : __mem_func__(eventFunc), 'arguments' : eventFuncArgs, 'run_next_time' : app.GetGlobalTimeStamp() + eventStartTime}) def Process(self): """ Processing the events. """ for index, event in enumerate(self.eventList): if event in self.eventLockedList: continue if app.GetGlobalTimeStamp() > event['run_next_time']: result = apply(event['function'], event['arguments']) if result in (None, self.EXIT): del self.eventList[index] continue event['run_next_time'] = app.GetGlobalTimeStamp() + result
@ulubey4242 You don't need cur_count and max_count, just do a simple max_count and decrease it until it's 0, that's all, you did things more complicated than are, but i like that there are people who want to improve it and do updates.
Then i've some tips for you, i hope you'll get them.
Btw, good idea about transform the list into dictionary, i leaved it like this because i wanted to make a compare functions too, if the admin call two times the same event < event, with differents settings but same name, i'd compare the events and merge them together with the same name (not replaced), that's why i leave a list, when i've some free time i'll post it, also if i'm the one which would do this from 0, i would change the full structure like event.cpp and do it in C++ combined with Python, i'll do it asap.
You used dictionary get method in function GetEvent, but you didn't returned it, so the function will return None.
has_key is a old thing, in is definitely more pythonic and faster than has_key, also it was removed in Python 3., you can use simple if key in dict like we do in lists.
The idea of the run count was to use it in parallel and for can be None as default argument. then the user have two options, using a function for X times and started to Y time and using a function for UNKNOWN times (from result of the event function until the return is 0) and started to Y times, what you did here have some conflicts and isn't a good idea, what's the scope of the returning function then, we should allow them to use one of the method.
Also you used del event, which is wrong, you deleted it locally from generator, not global, so the event will still run unlimited you need to use the DeleteEvent function for delete it properly.
You used a wrong method for loop, dictionaries aren't like list in loop, you have to use for event in self.eventDict.itervalues() for loop trough values of each dict, not for event in self.eventDict.
Ali vegas diyorki o count mantığı şöyle olucak diyelim event append ederken sadece count 10 girdik diyelim her eventden sonra count -= 1 olucak taki 0 olana kadar.Şöyle daha temiz;
Öğeyi görmek için üye olmalısınız.
Mantıklı tek key kullanılmış olur;Ali vegas diyorki o count mantığı şöyle olucak diyelim event append ederken sadece count 10 girdik diyelim her eventden sonra count -= 1 olucak taki 0 olana kadar.
Öğeyi görmek için üye olmalısınız.
@ulubey4242 You don't need cur_count and max_count, just do a simple max_count and decrease it until it's 0, that's all, you did things more complicated than are, but i like that there are people who want to improve it and do updates.
Then i've some tips for you, i hope you'll get them.
Btw, good idea about transform the list into dictionary, i leaved it like this because i wanted to make a compare functions too, if the admin call two times the same event < event, with differents settings but same name, i'd compare the events and merge them together with the same name (not replaced), that's why i leave a list, when i've some free time i'll post it, also if i'm the one which would do this from 0, i would change the full structure like event.cpp and do it in C++ combined with Python, i'll do it asap.
You used dictionary get method in function GetEvent, but you didn't returned it, so the function will return None.
has_key is a old thing, in is definitely more pythonic and faster than has_key, also it was removed in Python 3., you can use simple if key in dict like we do in lists.
The idea of the run count was to use it in parallel and for can be None as default argument. then the user have two options, using a function for X times and started to Y time and using a function for UNKNOWN times (from result of the event function until the return is 0) and started to Y times, what you did here have some conflicts and isn't a good idea, what's the scope of the returning function then, we should allow them to use one of the method.
Also you used del event, which is wrong, you deleted it locally from generator, not global, so the event will still run unlimitedm you need to use the DeleteEvent function for delete it properly.
Yes I already did as you said above,
Out of sight, thanks for the warning, @is_null; GetEvent fonksiyonunu güncellersin bu şekilde Öğeyi görmek için üye olmalısınız.
Okey, I've edited it. @is_null; DeleteEvent fonksiyonunu güncellersin bu şekilde Öğeyi görmek için üye olmalısınız.
I'il arrange it like you said yes.
DeleteEvent has the same function and control, Nothing but extension.
import time
timer = 1
while True and timer <= 60:
timer += 1
localtime = time.localtime()
result = time.strftime("%I:%M:%S %p", localtime)
print(result, end="", flush=True)
print("\r", end="", flush=True)
print("bool value: ", bool(timer <= 60))
time.sleep(5)
Teşekkürler fakat neden bu kadar uğraştığını anlamadım idle de denemeden bunu yazdım aynı işlevi görecek şekilde veya ben mi bir şey kaçırdım?
timer = 1
while True and timer <= 60:
timer += 1
localtime = time.localtime()
result = time.strftime("%I:%M:%S %p", localtime)
print(result, end="", flush=True)
print("\r", end="", flush=True)
print("bool value: ", bool(timer <= 60))
time.sleep(5)
Teşekkürler fakat neden bu kadar uğraştığını anlamadım idle de denemeden bunu yazdım aynı işlevi görecek şekilde veya ben mi bir şey kaçırdım?
Konudan çok uzaksın içerisinde örnek verdim. Bu yazdığın kodla bu tarz oyunlara gitmez + olarak time.sleep hangi düşünce ile koydun ne biliyim bu yazdığım kodları kullanıcak olanlar vardır konu ismindeki sistemi kontrol edersen ne işe yaradığını anlarsın.import time
timer = 1
while True and timer <= 60:
timer += 1
localtime = time.localtime()
result = time.strftime("%I:%M:%S %p", localtime)
print(result, end="", flush=True)
print("\r", end="", flush=True)
print("bool value: ", bool(timer <= 60))
time.sleep(5)
Teşekkürler fakat neden bu kadar uğraştığını anlamadım idle de denemeden bunu yazdım aynı işlevi görecek şekilde veya ben mi bir şey kaçırdım?
+ olarak bu bir event classı onlarca veya yüzlerce event gömebilirsin.import time
timer = 1
while True and timer <= 60:
timer += 1
localtime = time.localtime()
result = time.strftime("%I:%M:%S %p", localtime)
print(result, end="", flush=True)
print("\r", end="", flush=True)
print("bool value: ", bool(timer <= 60))
time.sleep(5)
Teşekkürler fakat neden bu kadar uğraştığını anlamadım idle de denemeden bunu yazdım aynı işlevi görecek şekilde veya ben mi bir şey kaçırdım?
Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)
Benzer konular
- Cevaplar
- 8
- Görüntüleme
- 495
- Cevaplar
- 1
- Görüntüleme
- 8
- Cevaplar
- 1
- Görüntüleme
- 5
- Cevaplar
- 1
- Görüntüleme
- 20