timtim's Forum Posts

  • I originally planned to do this earlier, but I've finally got a week off and I've been looking at Python some more, so here goes.

    For the first mini tutorial I'll focus on HTTP connections, primarily requesting web pages and getting data (which can then be parsed).

    Step 1, assembling a layout

    For this code, insert 2 edit boxes. The first should be called 'Query', and the second 'Result'. Add a button in which will act as the trigger to execute the python script.

    Step 2, making a HTTP query script

    For this piece of code, we'll be using the HTTPConnection object, which provides an interface for GET/POST without having to set up headers. So begin the script with:

    import httplib[/code:26ccsn3t]
    
    Because we don't want this to run all the time, define the code below as a function:
    
    [code:26ccsn3t]def SearchGoogle():[/code:26ccsn3t]
    
    The editor will then auto-indent so any following code will not be run every event loop (a mistake I made first time around ).
    
    Python is a very simple language syntax wise, so it's perhaps better to paste the entire function and then explain it:
    
    [code:26ccsn3t]
    	HTTPCon = httplib.HTTPConnection("www.google.com")
    	HTTPCon.request("GET", "/search?hl=en&num=10&start=1&safe=on&q=" + Query.Text)
    
    	Response = HTTPCon.getresponse()
    
    	if Response.reason == "OK":
    		Data = Response.read()
    		Result.SetText(Data)
    
    	HTTPCon.close()
    [/code:26ccsn3t]
    
    [i]HTTPCon[/i] is the HTTP connection which is instantiated (or created) from the python object, it is defined with a connection to "www.google.com". The next line builds the search string. We are using GET; the object also supports POST so you can build hi-score engines, or post data through applications. After that, define a response object and check that the query was 'OK'. Then simply read the data and put it into the Result edit box.
    
    Finally, add a condition for button clicked, and use the system action 'Run Script' and simply put in 'SearchGoogle()'.
    
    [b]Step 3, making a POST script[/b]
    Posting data works nearly exactly the same way, except we must also post parameters.
    
    For those who do not know how posting works, it is basically sending a form to a server, whether a cgi, php or asp script, which can then store the information or otherwise process it.
    
    Here's a small example (suppose you want to subscribe to updates):
    
    [code:26ccsn3t]
    	Data = "myemail@email.com"
    
    	HTTPCon = httplib.HTTPConnection("localhost")
    	HTTPCon.request("POST", "/Subscribe.php", Data)
    
    	Response = HTTPCon.getresponse()
    
    	if Response.reason == "OK":
    		Result.SetText("Subscribed")
    
    	HTTPCon.close()
    [/code:26ccsn3t]
    
    I couldn't actually find a suitable testing server or script for POST; if anyone finds one let me know. POST can also handle uploading of files to servers, via multi-part. I may touch on this in a future tutorial.
    
    Next though I'll look at direct connections through sockets.
    
    Tim
  • I just checked this out, seems to be a lot of hot air over very little.

    -Adam- whoever he is appears to be the instigator of most of the winding up here, what with his avatar and hypocritical statements. No need to stir things up though, both the communities have strengths and Rikus puts it perfectly, we're all here to create cool stuff. It's weird to think that people could get so uptight over computer programs.

    Tim

  • Also Python in 0.91 will have builtin socket support (even for SSL and such).

    When it comes out i'll write a basic tutorial on how to do stuff like grab a webpage, do a google search, etc.

    Hopefully then we can get some templates and articles on how to do online games with Construct through python.

  • That is really amazing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The object CAN save.. that's why I don't really understand this discussion.

  • Attan: I disagree 100%. We already have several 2D gamemakers to choose from. Anything to set Construct AHEAD should be added.

    I agree with this but more the point that 3D in 2D games doesn't work. I already mentioned Paper Mario but i'll mention it again because it's an amazing example of a 2.5D game <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" />.

  • I'm not sure you fully understand the purpose of the object. To me it seems it's meant to be used to modify files on disks (bmp, png files), more than to display and put effects on sprites onscreen which can be done via shaders.

  • I think machrider is correct in what he says. 2.5D is definitely achieveable and allows some awesome games (paper mario, anyone?).

    A mostly working SDL runtime is ready for testing in the next build hopefully. If that goes well I'll crack on with some OpenGL. 3D in OpenGL is very simple.. it would just need the IDE to be modified.

  • I don't see Ashley saying it was impossible for anyone.. one programmer can only do so much and to create a modeller, a WYSIWYG 3D editor and then tie it in with the ease of the collision system, effects and everything Construct has is asking years of development in ground that he probably hasn't worked in before.

    Not to mention the huge library of 3D objects and artists they have at their disposal. I doubt the majority of Construct users have the talent to create them!

    To me it seems Construct should continue with Direct-X/OpenGL and gradually add more 3D features, if and when additional programmers with 3D experience join then hopefully a 3D engine can be built onto the existing system.

  • From what I've read of python sockets, it'd be much easier to do your net code in python than via an object. Stuff like reading data from sockets is much better in code.

    I don't know how python is implemented in Construct but it should be possible for someone to write an easy to use socket class and then other users to put it in, so it'd be basically:

    Online.Connect("ip", 100)

    We'll see when it comes out.

    Tim

  • It looks like it supports multiple selection, so the parameter would be the file index you want to retrieve.

    Add 0 or 1 as a parameter, and see if it returns the correct path.

    Tim

  • OpenGL should be easy to plug in once SDL is fully working. I'll look into it soon enough.

    Tim

  • Common dialog has a file selector you can use with it I think.

    Tim

  • Sweet. I hope you find my code ok and it goes in soon.

    Tim

  • I've sent my work to Ashley and it looks as if he's integrated it with the codebase. We'll see what happens soon.

    Tim