0 Favourites

Python and System.GetToken

This forum is currently in read-only mode.
  • hi,

    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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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:

    def getToken(string, num, delimiter=','):
    	try:
    		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.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
35 3,128
deadeye's avatar
deadeye
Unread hot topic
0 Favourites
3D Python Camera
31 3,878
chrisbrobs's avatar
chrisbrobs
Unread hot topic
0 Favourites
Python - A quick look
30 8,508
Somebody's avatar
Somebody