Do I use Regex to compare the value of two instance vars?

0 favourites
  • 4 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • Hi,

    I've got 2 instance variables that both has String that I'd like to make a comparison of. I'm trying to make one of those typing games that take in the latest character typed and sees if the last character of the target word matches up. So I looked up the Regex function and I'm trying that out, but how do you enter the regex? Like for example, RegexSearch(). This takes in a String, Regex and Flag as parameters. Any clue as to how I can use this to search up instance var A using instance var B as a regex value? I'm a little confused as how the formatting goes.

    So I'm guessing I'm looking for something like:

    RegexSearch(InstanceVarA, /^InstanceVarB/, flags?)
    [/code:tjmg3i0q]
    
    So in JS, something like:  
    
    [code:tjmg3i0q]
    /^searchingforthisterm/.test("I am searchingforthisterm")
    [/code:tjmg3i0q]
    
    And is there a function to get the last character of a String?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You have to enter the regex and flags as strings.

    RegexSearch("I am searchingforthisterm", "^searchingforthisterm", "")[/code:2vub40wo]
    [code:2vub40wo]RegexSearch(VarA, "^" & VarB, "")[/code:2vub40wo]
    
    You can use the [b]right(text, count)[/b] expression to get the last character
    [code:2vub40wo]right("some text", 1)[/code:2vub40wo]
  • I'm not quite sure I understand..

    If you would like to compare if both instance variables are the same there are easier methods..

    object compare variableA = object.variableB

    if you'd like to know if variableB exists within variableA you could use the expression

    system compare two values : find(object.variableA,object.variableB) is not -1

    and if you'd just like to know if the last character of variableA is the same as VariableB

    system compare two values : right(object.VariableA, 1) = object.variableB

  • ramones - thanks for the tips, I'll try these!

    LittleStain - Thanks for the suggestions. I'm not sure myself. I'm still figuring this out - I'm trying C2 again so I'm still getting settled with this WYSIWIG interface. Ideally, I'd like to show, up to which characters typed by the user matches the target word then break when the user enters a character that doesn't match up.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)