question about menu and repeat

Please post any questions about developing your plugin here. Please use the search function before posting!
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

question about menu and repeat

Postby 8guawong » Sun Nov 23, 2014 10:45 pm

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()
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Nov 23, 2014 10:57 pm

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.
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Sun Nov 23, 2014 11:23 pm

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)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Nov 23, 2014 11:31 pm

Oh yeah, sorry, the name of your variable misled me. I would probably use a name more like player_repeats or player_repeat_dictionary.
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Thu Nov 27, 2014 10:21 am

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...
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 27, 2014 1:59 pm

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.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 27, 2014 6:01 pm

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.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Nov 27, 2014 7:28 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Nov 27, 2014 10:53 pm

He is probably using the release download which doesn't include the disconnecting fix and the stopping one.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Nov 27, 2014 11:27 pm

That just fixed resuming stopped repeats.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Thu Nov 27, 2014 11:43 pm

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!!
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Nov 27, 2014 11:52 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 27, 2014 11:53 pm

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.
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Fri Nov 28, 2014 12:03 am

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 ;)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Nov 28, 2014 11:26 am

Just do what L'In20Cible told you and the exceptions will be gone.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 19 guests