Python and System.GetToken

For questions about using Classic.

Post » Tue Aug 10, 2010 3:34 pm


if i try to call "System.GetToken("test1,test2", 2, ",")" with Python it always says "TypeError: NoneType object is not callable". i have test some different variants but it does not work. always the same error. i use construct 0.99.91.
Posts: 5
Reputation: 775

Post » Wed Aug 11, 2010 2:22 am

Hi. I haven't been able to get Python to work at all in Construct lately (not sure why, but may be due to re-installing Windows XP, somehow), so I can't test whether I can get that to work.

One thing that comes to mind: If you are using the 'System->Run Script' action or the 'System->Evaluate python command' expression, which must have the command enclosed in double-quotes("), then you should use the single-quotes (') around strings within those. No need to worry about that if you are inserting the script into the event sheet, though.

It may just not work, in which case you can roll your own with Python, if you like. For example, this would be very similar:

[code:lynp8a7d]def getToken(string, num, delimiter=','):
return string.split(delimiter)[num]
except IndexError:
return ''[/code:lynp8a7d]

It handles out-of-range indexes by returning empty strings, but indexes are zero-based instead of one-based, as Construct uses. It also allows negative indexes, which count backward from the end.

You can include your own functions like that by adding them into a 'Start of Layout' condition, since they need only be defined once.
Posts: 187
Reputation: 1,449

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests