How do I reference a group during a comparison

Get help using Construct 2

Post » Fri May 26, 2017 9:41 am

So, currently I have a system where I am checking a text value in my array.

it reads like
if array at position 0,0 = "symbol_01"
if array at position 1,0 = "symbol_01"
if array at position 2,0 = "symbol_01"

these are within a group called "symbol_01"

when i copy paste this code to adapt it for symbol_02, i need to click and replace every "symbol_01" with "symbol_02"

what i really want is to be able to say
if array at position 0,0 = "this groups name"

so i can just change the name of the group and not have to go into every condition, or something to this effect. I have the personal license. Thank you for reading.
B
4
Posts: 5
Reputation: 212

Post » Fri May 26, 2017 12:15 pm

Use a function.

Add Function object.

Add a separate block of events that starts with 'On function', here goes all the stuff that you want the function to do. I will refer to this as the function block.
Say we name it "CompareSymbol"

Function > On function ... Name = "CompareSymbol"
____Local variable 'Symbol' <---- not needed, but it is easier for the eyes.
____Empty sub event
__________ action: System > Set value .. Symbol to Function.Param(0) <--- i explain this later
____if array at position 0,0 = symbol < --- the local variable
____if array at position 1,0 = symbol
____if array at position 2,0 = symbol
__________ action: Function > Set return value ... value = 1
____else
__________ action: Function > Set return value ... value = 0

Now you have this block only once. And you can call it as many times as you want.
This action 'Function > Set return value' sets a special system variable. You can access it with an expression.
The value is there and has meaning direct after calling the function.
So, lets call the function.

Any condition that leads to comparing the Symbols.
____ Action: Function > Call function .. Name = same as in the 'On function'. In this case "CompareSymbol" .. parameter 0 = "symbol_02"
____ Sub event: System > Compare 2 values .. First = Function.ReturnValue .. equal to .. second = 1
__________actions: do the needed stuff when the array is matching the symbols
____ Else
__________actions: do the needed stuff when the array is NOT matching the symbols

With the expression 'Function.ReturnValue' you access the value that you have set with that action 'Function > Set return value ... value = 1' in the function block.

Now. When you call a function, you often have to pass values to the function block. Those are called the parameters. In this example, the function needs the value 'symbol'. We have set 'symbol' to Function.Param(0) in the function block. What is this ?

When you click the action Function > Call function ... you see that 'Add parameter' line in the UI. Click it to add a parameter. A new field appears to fill in a parameter with in index zero.
In that field you type the symbol that you want to call the function with. "symbol_01" or "symbol_02" .......

It is in fact always the same.
When you set a value in an action, there is (almost always) an expression to access that value.

Action : On function'... name ="CompareSymbol" .. parameter 0 = "symbol_02"
Access that parameter with Function.Param(0)

Action : Function > Set return value ... value = 1
Access that return value with Function.ReturnValue

Same as the more common
Action: Sprite > Set X ... X = 150
Access that X with Sprite.X
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat May 27, 2017 11:44 am

Hey 99instancs2go! you're and absolute legend mate! this is extremely comprehensive and must have taken a long time to write up so thank you very much for putting the effort in, the construct community always delivers.

While this has some information in here that I still don't quite understand fully just yet, I got so far down and it started to not be applicable to what my specific game framework is, however, i did manage to use this information to achieve my desired effect. Mainly that you can take a global variable and drag it into a condition to convert it to a local variable!

using this local variable (as a substitute for the "this group name" from my OP) I can now repeat my symbol conditions and change only the local variable in each condition and not have to go into each sub event and change their individual conditions. PERFECT!

____if array at position 0,0 = symbol < --- the local variable
____if array at position 1,0 = symbol
____if array at position 2,0 = symbol

So if any of the other newbies out there read this, then that's a quick way to not have to change all your sub events with the same conditions when you copy/paste.

I actually haven't needed to use the rest of the post, just yet. As my code is working as intended just from this local variable.

so I have,

Set [local variable text] to symbol which = "symbol_01"
if array value at 0,0 = symbol <local variable
--then if array value at 1,0 = symbol <local variable
----then if array value at 2,0 = symbol <local variable
-------then system [add coins] only trigger once.
*[add coins] i have another array that stores the win values for each symbol.

then all i do is paste. and change local variable to "symbol_02"

Set [local variable text] to symbol which = "symbol_02"
if array value at 0,0 = symbol <local variable
--then if array value at 1,0 = symbol <local variable
----then if array value at 2,0 = symbol <local variable
-------then system [add coins] only trigger once.

SO long story short you can use a local variable to the same effect as a "this block(group) of conditions name" expression.

All the information about parameters and return values is going over my head atm but is on my list to wrap my head around, i need to do some further personal research into those! again, thank you!
B
4
Posts: 5
Reputation: 212


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests