Jump to content

  • Log In with Google      Sign In   
  • Create Account

Herwin P

Member Since 09 Apr 2013
Offline Last Active Oct 09 2014 06:47 AM

Topics I've Started

Need Help With Twisted Deferred

16 July 2013 - 01:07 AM

Terribly sorry. It was just a small mistake. I've fixed it. I forgot that I should have returned the deferred object. Sorry everyone.

 

Spoiler

Question About Game State

21 June 2013 - 11:11 PM

Nevermind.


How can I avoid circular dependency?

28 May 2013 - 08:06 PM

I often meet a condition in programming where I have a class which takes an instance of another class and makes use of some functions in that imported class, while that class also needs some functions in the first class.

 

Like class A has function x() and y(), and class B has function i() and j(). Class A needs to use function i() in class B, and function j() in class B needs to use function y() in class A.

 

How can I reduce this to minimum? Is there any better way to do this? For some reasons, function y is only available in class A.

 

Oh, almost forgot this question. How can I do this the right way?

 

Thank you everyone.


Python Twisted: need help on deferred

24 May 2013 - 12:00 AM

Hi everyone. I'm writing a Twisted based daemon for a simple text-based multiplayer game. The game logic goes like this. The client sends a string in a particular format (command.arguments (also separated by period)) to the server. The server receives that string, split it, and run the command along with the arguments. I already made it working.

 

Some of the commands called (login for example) has to get data from database. I'm using Twistar to make things fancy.  Here's where I found some difficulties. The function which calls the available commands returns the result of the called command. The problem is that I don't know how to make my login function to return the result of the query.

 

Simply, what I want : send strings (or list, or number, or whatever) gained from the database to the client.

What I get now : the server sends a deferred object or an empty string or list (I've tried some ways to send things to the client).

 

I know it sounds so newbie, but this is my first Twisted program, and I'm still learning, so please spare me.

 

Well, I think the scripts will make things clearer:

 

The server.py.

Spoiler

 

The protocols.py

Spoiler

 

The services.py

 

Spoiler

 

There's no complicated logic yet. I started writing this thing just three days ago.

 

The deferred does fire. It prints the "bla bla bla logged in" properly.

 

The client is just a simple client which sends 'login.Sky Warden.123'. The arguments will be separated by the '.' as well.

 

I think that's all. Maybe it's just me who don't fully understand deferreds, or it's just a logic hole. Or maybe both. XD

 

Thank you everyone. smile.png


Python Twisted question: need help on deferred

22 May 2013 - 08:06 PM

Hi everyone. I'm writing a Twisted based daemon for a simple text-based multiplayer game. The game logic goes like this. The client sends a string in a particular format (command.arguments) to the server. The server receives that string, split it, and run the command along with the arguments. I already made it working.

 

One of the command called has to get data from database. I'm using Twistar to make things fancy.  The problem is, I need to return the result of the deferred made by the query. I know it sounds so newbie, but this is my first Twisted program, and I'm still learning.

 

Well, I think the scripts will make things clearer:

 

The server.py (don't worry, it's inside a code tag):

Spoiler

 

The protocols.py

 

Spoiler

 

The services.py

Spoiler

 

I'm sure the error is in the login function. I think it's like saying "Wait. My result isn't here yet" by returning a deferred, but it will be the deferred which is sent to the client.

 

Well, there's no complicated logic yet. I started writing this just two days ago. All I want is to send the query_result.username to the client. The query is fine. I can print that thingy on the server.

 

What I want : the login() function returns the result of the query (a list, string or whatever) so I can send it to the client.

What I get : the login() function returns a deferred object.

 

The client is just a simple client which sends 'login.Sky Warden.123'. The arguments will be separated by the '.' as well.

 

I think that's all. Maybe it's just me who don't fully understand deferreds, or it's just a logic hole. Or maybe both. XD

 

Thank you everyone. smile.png


PARTNERS