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

Get help using Construct 2

Post » Thu Apr 23, 2015 11:32 am

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:

Code: Select all
RegexSearch(InstanceVarA, /^InstanceVarB/, flags?)


So in JS, something like:

Code: Select all
/^searchingforthisterm/.test("I am searchingforthisterm")


And is there a function to get the last character of a String?
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Thu Apr 23, 2015 11:46 am

You have to enter the regex and flags as strings.

Code: Select all
RegexSearch("I am searchingforthisterm", "^searchingforthisterm", "")

Code: Select all
RegexSearch(VarA, "^" & VarB, "")


You can use the right(text, count) expression to get the last character
Code: Select all
right("some text", 1)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Apr 23, 2015 11:54 am

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 23, 2015 4:14 pm

@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.
B
7
S
1
Posts: 42
Reputation: 1,058


Return to How do I....?

Who is online

Users browsing this forum: Apollo14 and 32 guests