scidave's Recent Forum Activity

  • You can use fetchone() to get the rows one at a time, or fetchall() to get them all at once.

    So it is just a difference in syntax. If you had a massive databse then to save on memory you might want to use fetchone(), but in your case it doesn't practically matter which one you use.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This while(1) from the first code means what?

    it's true?

    It means loop forever.

    instead of print I should use SetText right?

    Correct. I was just showing an example you could test in straight Python.

    Also, what is the difference retrieve as python dictionaries? didn't understood what u meant by index..

    If the result is return as a Tuple (a List) and you just print out the Tuple you will get a funky looking "('TESTER,')" <----a Tuple with only one entry. Instead if you said row[0], that would just return "TESTER" as it is the first element/index in the row.

    All of this is just a guess as I actually haven't tried this out in code..don't have my computer with the database on it with me right now...I might be wrong on some of this.

  • The results are usually returned as a Tuple or if nothing is available the result will be None. So you should access the result as a Python list.

    For example:

    cursor.execute ("SELECT name, category FROM animal")
       while (1):
         row = cursor.fetchone ()
         if row == None:
           break
         print "%s, %s" % (row[0], row[1])
       print "Number of rows returned: %d" % cursor.rowcount
    [/code:3q411di1]
    
    You could also retrieve the rows as Python dictionaries to retrieve results by name (and not index):
    
    [code:3q411di1]
    cursor.close ()
       cursor = conn.cursor (MySQLdb.cursors.DictCursor)
       cursor.execute ("SELECT name, category FROM animal")
       result_set = cursor.fetchall ()
       for row in result_set:
         print "%s, %s" % (row["name"], row["category"])
       print "Number of rows returned: %d" % cursor.rowcount
    [/code:3q411di1]
    
    Hopefully, that was the problem!
  • You are defining a function over and over again on every tick. With Python's garbage collection this will be slow (and not needed)

    Good point! After taking the screenshot and posting I realized that and then got too lazy to repost. Plus your use of Python is much cleaner over all.

    So go with Tulamide's example...it is much better!

  • Here is an example of what I was trying to show with the temp == 0 approach:

    NOTE: This assumes you have to set the initial value of temp in the move function..obviously in this simple example it would make more sense to just set it to start on layout.

    <img src="http://i52.tinypic.com/2uyjhiq.png">

    .cap download:

    http://www.box.net/shared/kytvo2uq4h

    Pyshell.cap came in handy looking for Python commands...If you don't use it I would encourage anybody that uses Python to try it out! It is in one of Silent Cacophany's posts.

  • Well, how does the AppPath thing in Construct work? I would take a look at that and try to... er, copy it .

    I already know how to get the AppPath (Call GetModuleFileName to obtain full path to currently running .exe and then strip off the file name with a strchr()). That way I could always save the file in the same directory as the executable.

    What confuses me is when I run Noga's game on my computer it works correctly (saves the screenshot in the same directory as the .exe). But when I build a .exe myself it saves the screenshot to a working directory). That part doesn't make any sense...but I'll implement what I believe will fix it.

    I should add option to pick save location as well.

    Edit: Ok, fixed the bug...I think. I have the picking size of the BMP on my TODO-list.

    New version: http://www.box.net/shared/i28fdpvfj0

  • Glad folks are finding this useful!

    I had wip folder with the game's cap and plugin saved screenshots into the cap's folder, but when I exported the game into different folder and run the exe, it saved the screen into the cap's folder. I had to export the exe into the same folder as cap file, than it works.

    Thanks for the bug report. I'm not sure a good solution to this problem. It seems to work just fine for the executable you made, but you are correct that it does weird things between where the exe is saved and where the WIP folder is on the developer's machine.

    If I set the current working directory to the directory of the current running executable then when you are using construct it will save to either scirra/contruct or a temp folder. But it would solve the problem I think. Another option is to specify the save path...but we don't know where folks will put their executable when they get it.

    Does anybody have an idea on a good solution to this?

    In the meantime, I'll take a look at making configurable sizes to save them to (or at the least a small, medium, large).

  • You could do this in Construct as well (System compare with a global variable..say x). Just have an if statement that says, "if x ==0 " then set your variable.... then the first time it happens set x = 1. That way the variable will never be set again after that.

  • I have looked over some tutorials but they are either out of date to where things are in the program, or not completed, or both.

    While most of the tutorials are older, I wouldn't say they are "out of date" or not relevant. There are enough working tutorials to get you up and running quick.

    This one is still relevant:

    There are a bunch of other useful tutorials...look at JamesX list...download stuff and just try them out.

  • Fun game! and the computer AI was pretty neat too. I didn't do as well as you, but liked the gameplay.

    <img src="http://i52.tinypic.com/243mbtk.jpg">

    Edit:

    For midi, you could try Pysonic"

    http://sourceforge.net/projects/pysonic/

    Unfortunately, there is no build for 2.6 so you would have to build it from source. It is kinda old too so I'm not sure how good its midi support is. Somebody should write a plugin for FMOD (at least the midi portion) .

  • Awesome! Glad to hear things are working good. This is indeed a great thread to learn database access.

  • Maybe is something about the GRANT privileges? I've readed something about it but not sure if could be it, it seems to allow accounts privileges, but they are connecting with the root username, should then I make a new account with some privileges just for remote access?

    I think this is probably your problem since you have the ports forwarded.

    You want to limit what users can do so they don't dork up your database.

    For example you could do the below to allow the user "bar" to do anything on database "foo"

    GRANT ALL ON foo.* TO barhtu@?%? IDENTIFIED BY ?PASSWORD?;

    Ideally, you would create a separate account, as you mentioned, that has less privileges than your root account.

    http://dev.mysql.com/doc/refman/5.1/en/ ... users.html

scidave's avatar

scidave

Member since 4 Jul, 2009

Twitter
scidave has 1 followers

Trophy Case

  • 15-Year Club
  • Email Verified

Progress

16/44
How to earn trophies