Calling 2 variables in one expression

Get help using Construct 2

Post » Sun Sep 22, 2013 4:59 pm

hello,
in my game developing i needed some help today. I want to call an instance variable : char.currentweapon
then say, bullet set speed > (gun & char.currentweapon).bltpower
how is it possible to do this

(hope you understand the problem.)

thanks ash12212013-09-23 11:08:31
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Sun Sep 22, 2013 6:18 pm

System > Compare Two Values >
You can put what to compare in the values.

I use this all the time:
Variable 1
select >
Variable 2
Returns true/false
DUTOIT2013-09-22 18:23:21
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Mon Sep 23, 2013 11:08 am

Oh,
but i am sorry @DUTOIT
that > sign was misleading. Sorry
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Mon Sep 23, 2013 12:05 pm

:SYSTEM
=COMPARE TWO VALUES

Put what ever variables you want to compare in value 1 and value 2. Choose greater than, less than, equals etc what ever you want to use

And it will return true or false.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Mon Sep 23, 2013 2:25 pm

@Ash1221
I'm sorry, your example isn't clear. Please describe what you want to achieve without using pseudo code. In your example I'm unable to tell if & should represent a logical AND or the building of a string. Also, what is the content of 'currentweapon', a number, a text? What do you want to differentiate using it? Etc.
Better describe a scenario, so that we can better follow your thoughts.tulamide2013-09-23 14:26:40
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Sep 23, 2013 2:47 pm

sorry @tulamide
i had a lot of trouble with this problem but then i had a think about it and i found it would be easier to use events instead of variables.What i was trying to do was this:
take three sprites: s1 , s2 , player
(the first 2 have different variables with same names)
so if the value of player's variable (currentWeapon)
then we would get the variable of .."s" & currentWeapon .. , which would give us either s1 or s2.
since s1 and s2 have different variables with same names
i would do :: s1 or s2 (which would be determined by the earlier code) then pick the variable of the S's (e.g. s(1/2).power)
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Mon Sep 23, 2013 3:00 pm

I think I get what you're meaning, but typically this type of functionality would require the use of a function pointer in a low level language, or a dynamic runtime compilation i.e. codeblock or macro. I don't think there's anyway to build a variable name dynamically at runtime within C2.
B
14
S
6
G
1
Posts: 143
Reputation: 1,800

Post » Mon Sep 23, 2013 5:05 pm

Well, actually there is at least a way to reduce the amount of events needed. By using a function. Example:
[code]
+ function | on "get_power"
   + function | parameter 0 = 1 -> function | set return value to s1.power
   + function | parameter 0 = 2 -> function | set return value to s2.power
   + function | parameter 0 = 3 -> function | set return value to s3.power
   etc.

+ ... -> bullet | set speed to function.call("get_power", char.currentweapon)[/code]
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Sep 23, 2013 6:36 pm

Oops, completely miss understood the question. The > threw me off.


@tulamide, I spy with my little eye something beginning with "P" Answer: PRO, spot the pro DUTOIT2013-09-23 18:38:28
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests