Python

For questions about using Classic.

Post » Mon Oct 11, 2010 6:56 pm

[quote:lhqhdp1s][quote:lhqhdp1s]
In my game, I use the OID of sprites a lot. However, Construct has for, some reason, given two sprites the same OID. Is this normal?[/quote:lhqhdp1s]
It is normal, OID is unique for each object type, so two instances of the same type will have the same OID.[/quote:lhqhdp1s]
Sorry, I didn't clarify. They were two different objects, not different instances of the same type. I don't think it could have been a mistake since it worked before, but I'll never know now since I got rid of the OID part of my project and converted it in private variables.
[quote:lhqhdp1s]You want to use UID, it is unique for each object, so no two objects will ever have the same UID.[/quote:lhqhdp1s]
Thanks, I think this will help with an issue I'm having of choosing which instance of the object.

Edit: Is there a limitation on how many lines of script you can have?
I got up to 65 and nothing after line 65 gets executed.
B
2
G
2
Posts: 48
Reputation: 746

Post » Mon Oct 11, 2010 9:02 pm

There shouldn't be any limit to python scripts. I was able to run a 100 line script without any issues.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Oct 11, 2010 10:12 pm

[quote="RomanCenturion":32womvdf][quote:32womvdf]you might be able to save sometime by using a dictionary[/quote:32womvdf]
That's probably a good idea. Could this be used to substitute for an array? I wouldn't be using it to save the game, but it would store values with 3 keys (ex. (x,y,z) or (1,2,1)).[/quote:32womvdf]

Though it's a bit irregular, a dictionary using tuples as keys can be used as a sort of multi-dimensional array. Also, a dict's get() and setdefault() methods can provide easy handling of cases where keys are not there yet. Here's a simple example:

http://www.daniweb.com/code/snippet275835.html

With that pointed out, I'd just use lists in most cases.

[quote:32womvdf]Edit: Is there a limitation on how many lines of script you can have?
I got up to 65 and nothing after line 65 gets executed.[/quote:32womvdf]

I've got a few scripts well longer than that, with no problems.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Mon Oct 11, 2010 11:49 pm

[quote:2h1rx0he]There shouldn't be any limit to python scripts. I was able to run a 100 line script without any issues.[/quote:2h1rx0he]
[quote:2h1rx0he]I've got a few scripts well longer than that, with no problems.[/quote:2h1rx0he]
I don't know why, but it's just ignoring the lines of script. Your'e probably right about it not being limited though, I switched a few lines around with the same result.
Thanks for the link Silent Cacophony, it looks helpful. :D

Edit:Could someone show a simple way of making and getting information from a dictionary in construct? I'm not doing something right and it's frustrating not being able to figure it out.

I found out how to do it :D
[code:2h1rx0he]
d1{}
d1[1,1,1] = "Hello"
d1[1,1,2] = "Bob"
...
Text.SetText(d1[1,1,1] + " " + d1[1,1,2])
#Sets text of Text to "Hello Bob" without the quotes
[/code:2h1rx0he]
B
2
G
2
Posts: 48
Reputation: 746

Post » Tue Oct 12, 2010 10:25 pm

I was wondering how to use the MouseKeyboard on object clicked event in python. I was able to get this far:
[code:20m0o9c6]MouseKeyboard.OnClickObject(left,single,Object)[/code:20m0o9c6]However, "single" isn't the correct syntax. Any idea on what to use instead? Thanks.
B
2
G
2
Posts: 48
Reputation: 746

Post » Wed Oct 13, 2010 11:13 am

For object parameters use the object name in quotes.
For combo parameters use a number (0 for the first choice, 1 for the 2nd and so on).
[code:2s8jsalz]MouseKeyboard.OnClickObject(0,0,'Object')[/code:2s8jsalz]

Be warned though, "On object clicked" is a triggered condition. Triggered conditions only work in events, they will not work in a python script.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Wed Oct 13, 2010 9:10 pm

Thanks for letting me know about triggered conditions not working in Python. I can probably get around it by putting python as a sub-event to the MouseKeyboard action.
Also, helpful to know combo parameters.
Thanks a lot everyone! I can't wait to finish version 0.1 of my game. :D
B
2
G
2
Posts: 48
Reputation: 746

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest