Python question - "Answered :)"

This forum is currently in read-only mode.
  • So i have working python code... for python.

    i have gone into application mode with construct to make the python code for buttons instead of having to type it out in my normal python exe i made.

    I have entered the python into the Event sheet editor, and when i run the application is does not show any errors, however, thats all it does.

    i need it to, when i click a button, show in a window what the python code would normally print out.

    e.g; i click randomize tab and it runs a .py script and displays the randomized number in a message box or text on the application.

    thanks in advance, i may have said the same things twice >.<

    edit: here is the code, i want the result to be displayed in a window after clicking a button.

    import random

    cox=random.randint(0,8)

    ranchar=['a','b','c','d','e','f','g','h','i']

    print "\n"

    print ranchar[cox]

    p.s constructs python uses 0 indexing right?

  • On button click -> Text.Text = Python("cox")

  • Text.Text = Python("cox")

    Where exactly am i meant to add this at?

    This is what i do:

    1. New script, add the script stated in the first post exactly

    2. Make a "On button click" for that particular button, lets call it 'x'.

    3. When button is clicked -> System -> Run Script -> and i enter Text.Text = Python("cox")

    I can only guess im doing something wrong. Help appreciated, thanks for your reply SuperV.

  • nvm, fixed this part of it (the undefined)

  • > Text.Text = Python("cox")

    >

    Where exactly am i meant to add this at?

    It might not be too clear in SuperV's post but you need a text object to put your text into. It won't just appear in a command window or randomly on the screen. Right-click the layout and click "Insert an object" and pick Text (or whatever it is you want to put your text into).

  • Well i made the text, and i can get something to appear after clicking a button but all it is is an integer or either 0 or 1, 0 more commonly.

    So yeah im still stuck, but have been trial and erroring this this for ages

  • Well i got it to do what i what, though it comes up with an error every so often, one which doesn't really explain where the problem occurs..

    <img src="http://img301.imageshack.us/img301/105/porblemiw9.jpg">

    this also happens in exe version. apart from that, if anyone can help me with my error, ill be more than grateful (very pleased with help thus far)

    p.s my script only has 5 lines so... hmmm thats why im confused with the message.

  • Instead of 'print randchar[cox]', you just need an ordinary Set Text action with a String object. As the expression for the text, you can enter Python("randchar[cox]") - this expression evaluates the Python variable and returns it to Construct. That should do what you need.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Everything is working and understood. thanks to everyone for their help, much appreciated

  • Using 'print' command to dump message at development period is import for me, so that I wrote a small application to let 'print' command work in construct.

    Tool can be download at

    sites.google.com/a/binhua.twbbs.org/construct-project/FileStorage/MessageConsoleClient.7z

    I use a named pipe client to send 'print' message from construct to my named pipe server application.

    The instruction of using this tool is,

    1. open named pipe server application MessageConsoleServer\MessageConsoleServer.exe

    2. execute construct application

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)