Checking for two separate words in a text field

For questions about using Classic.

Post » Sat Mar 24, 2012 2:01 am

I'm trying to implement a command input window in my game (pretty much like debug console functions in certain PC games) and I'm currently having trouble regarding a certain function.

Say I want to spawn a coin worth 5 gold, I'd create an event where if when you press "RETURN" and the text displayed is ".spawncoin5g" then it'll spawn one of that object, that's all working fine.

But if I want to spawn 10 of those with just one command like ".spawncoin5g 10" how can I code it so that the system checks for two separate words?

Any help is much appreciated.
B
5
S
1
G
1
Posts: 9
Reputation: 469

Post » Sat Mar 24, 2012 5:17 am

1) Start by isolating the string beginning with ".spawncoin5g":
substring = Right(theOriginalString, Len(theOriginalString)+ 1 - Find(".spawncoin5g", theOriginalString))

2) Now look at the second token, if any:
+ NumTokens(substring, " ") > 1
-> spawnnumber = int(GetToken(substring, 2, " "))
+ Else
-> spawnnumber = 1

substring and spawnnumber are variables, of course.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Mar 24, 2012 11:36 am

Much thanks for the help tulamide, I suspected it had to do with substrings but I didn't know how exactly to use them.

I'll try and play around with it later with your guide and hopefully I'll be able to get it to work.
B
5
S
1
G
1
Posts: 9
Reputation: 469


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests