scidave's Forum Posts

  • This was a really neat example. I especially liked the boxer on the left...funny looking guy.

    p.s. You set a new record for examples cranked out!!

  • Very nice example! I'll have to remember this for easy pseudo-plugin type work...

  • This syntax should work:

    System.CreateByName("objB", 1, 0, 0)

    SOL.objB.SetPositionToObject("objA", "point")

    Note: The quotes around objA.

    There might be a bug in the other function as the prototype shows it takes the # of arguments you are sending... maybe ROJO has an idea.

  • I'm curious more for my knowledge... Always interested in how people are using Python and if there are more efficient ways to do stuff.

  • But i wonder, why the scripteditor does not detect such syntax?? does it need a fix?

    Yes, a fix is definitely needed. Python integration has gotten a lot better in the last few releases pretty much all due to ROJOhound, but yes it could be better.

  • Is it possible in construct to create special scripts in python and pass to one of functions (or classes) in the script one or more of the construct objects as a parameter ? or send a new object from the script to construct ?

    Do you have an example of what you are trying to do? I'm not sure why you would need to pass Construct objects as parameters to Python functions since you can already access objects in local event sheets or globally if object is Global.

    On the flip side, how would Construct be able to operate on a new Python object? I guess I don't fully understand the question.

  • import random

    if MouseKeyboard.OnKey('A'):

    Text.SetText("Hi Mom")

    Sprite.SetValue('sizeaccel', (random.choice(array1)))

    Create a text object and use it to debug your program and you can use the debugger as well. For example, to see if your code is functioning right you can put a SetText call to see if that code is reached. I don't have Construct with me at the moment so not sure your syntax is correct or not....but you should try setting the 'sizeaccel' value to let's say "1" to debug that portion of your script.

    I think you need a "do once" type event for this as well since you only want that code executed one time you press the A key.

    EDIT: This post will help you (this question sounded familiar

  • e7 was really cool. Very smooth and eerie ambiance...I made it to about level 13 and then had my browser closed accidentally.

  • Yes, SOL is what you want. The post from ROjohound in this thread is what you are looking for:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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