0 Favourites

Checking for two separate words in a text field

This forum is currently in read-only mode.
  • 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.

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

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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. <img src="smileys/smiley4.gif" border="0" align="middle" />

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 Locked topic
198 18,656
Tom's avatar
Tom Construct Team Founder
Unread hot topic
0 Favourites
[Plugin] tag text
188 25,441
RBuster's avatar
RBuster
Unread hot topic
0 Favourites
3 word story
120 11,703
MPPlantOfficial's avatar
MPPlantOfficial