Page 1 of 1

question about menu and repeat

Posted: Sun Nov 23, 2014 10:45 pm
by 8guawong
trying to port my quiz script from ES to SP
but think i might end up with same problems as http://forums.eventscripts.com/viewtopi ... cbb1369e93

my ES quiz script

Syntax: Select all

def create_quiz_menu(userid):
global solution, operator
op1 = random.randint(1,15)
op2 = random.randint(1,15)
operator = random.choice(["+", "-", "*", "/"])
if operator == "+":
solution = op1 + op2
elif operator == "-":
solution = op1 - op2
elif operator == "*":
solution = op1 * op2
elif operator == "/":
solution = op1 / float(op2)
solution = round(solution, 2)
fsolution = solution + 1
fsolution2 = solution + 2
fsolution3 = solution - 1
fsolution4 = solution - 2
solutionlist = []
solutionlist.append(solution)
solutionlist.append(fsolution)
solutionlist.append(fsolution2)
solutionlist.append(fsolution3)
solutionlist.append(fsolution4)
quiz_menu = popuplib.easymenu('%s_quiz_menu' % (userid), 'popup_choice', quiz_menu_select)
quiz_menu.settitle("%s %s %s = ???" % (op1, operator, op2))
random.shuffle(solutionlist)
for solutions in solutionlist:
quiz_menu.addoption(solutions, "%s" %solutions)
quiz_menu.timeout('view', 3)

def quiz_menu_select(userid, choice, popupid):
if choice == solution:
reward(userid, 0)
else:
punish(userid)


and how would i use individualized repeat???

maybe this?

Syntax: Select all

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
my_repeat[userid] = TickRepeat(welcome)
my_repeat[userid].start(1, 10)

@Event
def player_disconnect(game_event):
userid = game_event.get_int('userid')
my_repeat[userid].stop()

Posted: Sun Nov 23, 2014 10:57 pm
by satoon101
We don't use 'names' for our menus. You instead create a new instance each time. Maybe someone else can provide an example, as I am on my phone.

As for the repeat, TickRepeats are not inherently dictionaries. You could pass the userid as an argument to your 'welcome' function or create a dictionary to store TickRepeat instances for each userid.

Posted: Sun Nov 23, 2014 11:23 pm
by 8guawong
satoon101 wrote:create a dictionary to store TickRepeat instances for each userid.


isn't that what i'm doing?

Syntax: Select all

my_repeat[userid] = TickRepeat(welcome)

Posted: Sun Nov 23, 2014 11:31 pm
by satoon101
Oh yeah, sorry, the name of your variable misled me. I would probably use a name more like player_repeats or player_repeat_dictionary.

Posted: Thu Nov 27, 2014 10:21 am
by 8guawong
is there something like gamethread.listDelayed() for repeat and tickdelay??

for some reason my repeats aren't getting stopped

http://forums.sourcepython.com/showthre ... 8#post3878

could it be this

Code: Select all

11-27-2014 17:25:35 - sp   -   EXCEPTION
   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/events/listener.py", line 90, in fire_game_event
    callback(game_event)
  File "../addons/source-python/packages/source-python/menus/base.py", line 326, in player_disconnect
    index = index_from_userid(event.get_int('userid'))

ValueError: Conversion failed...



--- edit ----
i think i know why...correct me if i'm wrong
player_activate once very map
palyer_connect only on connection
so another repeat started on map change

also try not to use the player_helper just get the variable from event to avoid
errors like below

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/events/listener.py", line 90, in fire_game_event
    callback(game_event)
  File "../addons/source-python/packages/source-python/menus/base.py", line 326, in player_disconnect
    index = index_from_userid(event.get_int('userid'))

ValueError: Conversion failed...

Posted: Thu Nov 27, 2014 1:59 pm
by satoon101
Yes, you are getting an error prior to stopping the repeat, so your repeat is never stopped. Players are not on the server when player_disconnect is fired, so you cannot get their index. Though, it seems you get the index and steamid for no reason whatsoever, as you never use those values in that event.

Posted: Thu Nov 27, 2014 6:01 pm
by satoon101
Oh, sorry, I looked at your code in the other thread you linked to, and didn't realize that the error comes from the menus package. That is something we will need to fix in the code.

However, the code in your other thread does not use menus, and should not be affected by the specific error you posted. It does have to do with what I wrote in my previous post, though.

Posted: Thu Nov 27, 2014 7:28 pm
by Ayuto
This issue has been already fixed. https://github.com/Source-Python-Dev-Team/Source.Python/issues/22

The problem in your code could be that player_spawn fires twice. So, two repeats are created, but only one will be stopped.

Posted: Thu Nov 27, 2014 10:53 pm
by L'In20Cible
He is probably using the release download which doesn't include the disconnecting fix and the stopping one.

Posted: Thu Nov 27, 2014 11:27 pm
by Ayuto
That just fixed resuming stopped repeats.

Posted: Thu Nov 27, 2014 11:43 pm
by 8guawong
thanks guys i went and updated my SP with the links from above

btw how do i just download the file from the links above?? instead of having to find the file and editing it by myself
can't find the download link to the specific file!!

Posted: Thu Nov 27, 2014 11:52 pm
by L'In20Cible
Ayuto wrote:That just fixed resuming stopped repeats.
Good point. I thought that was added to "start" and not "resume".

8guawong wrote:thanks guys i went and updated my SP with the links from above

btw how do i just download the file from the links above?? instead of having to find the file and editing it by myself
can't find the download link to the specific file!!
On this page, right click on [RAW] and download the target file.

Posted: Thu Nov 27, 2014 11:53 pm
by satoon101
The best way is to build your own SP build:
http://wiki.sourcepython.com/pages/Tutorials:Building_on_Windows

If your server is on Linux, there are a few differences in how that is done, but we don't have the wiki page for that done, yet.

Posted: Fri Nov 28, 2014 12:03 am
by 8guawong
my server is linux
but i think changing to player_connect fixed my problem
but it'll be good to see those exceptions gone from the logs ;)

Posted: Fri Nov 28, 2014 11:26 am
by Ayuto
Just do what L'In20Cible told you and the exceptions will be gone.