Python question - "Answered :)"

For questions about using Classic.

Post » Sun Feb 24, 2008 3:58 am

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?
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Sun Feb 24, 2008 1:14 pm

On button click -> Text.Text = Python("cox")
B
2
S
2
G
5
Posts: 512
Reputation: 2,674

Post » Mon Feb 25, 2008 5:08 am

[quote="SuperV":viuw1lvf]Text.Text = Python("cox")[/quote:viuw1lvf]

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.
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Mon Feb 25, 2008 5:24 am

nvm, fixed this part of it (the undefined)
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Mon Feb 25, 2008 5:47 am

[quote="Maev":y5bjbphh][quote="SuperV":y5bjbphh]Text.Text = Python("cox")[/quote:y5bjbphh]

Where exactly am i meant to add this at?[/quote:y5bjbphh]

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).
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Feb 25, 2008 7:11 am

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
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Mon Feb 25, 2008 7:23 am

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..


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.
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Mon Feb 25, 2008 9:24 am

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Tue Feb 26, 2008 5:12 am

Everything is working and understood. thanks to everyone for their help, much appreciated :)
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Thu Aug 18, 2011 7:39 am

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
https://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 applicationrexrainbow2011-08-18 07:44:02
B
97
S
22
G
179
Posts: 4,124
Reputation: 104,555

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests