How do I Grab the sum of instance varibles from two instance

Get help using Construct 2

Post » Fri Feb 27, 2015 8:03 am

Lets say you have a player object, and you use the UID to separate them within scripts. I am trying to create a co-op system where they have their own score but have x score to each which multiplies each stage. I want to grab the sum of each instances score. How would I do that.

Basically
Instance one score = 25
instance two score = 50

so I want to do a test of
if player.UID(1).score + player.UID(2).score > goal

Goal being a global variable, set prior. But I don't know how too do that, as it doesn't accept that in expression fields.

The reason for this being there is a co-op & vs mode I am trying to make, & trying to create shared scripts for different game modes.
Need custom controls, video & sound options, and a PC like menu system with screenshot manager?
Image
B
20
S
4
G
2
Posts: 36
Reputation: 2,431

Post » Fri Feb 27, 2015 12:12 pm

You can just make a variable called "Combined_ score".

Code: Select all
Set Combined_score = 0
For each Player
       Combined_score = Combined_score + Player.score

If Combined_score > Goal

B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801

Post » Fri Feb 27, 2015 12:13 pm

global var scored

function scorecounter
event
pick instance by unique ID = function.param(0)
action
set scored to instance.score
event
pick instance by unique ID = function.param(1)
action
add instance.score to scored




use

function(UID1,UID2)


and

event
scored > 50
action
go nutts
Who dares wins
B
53
S
13
G
11
Posts: 1,758
Reputation: 13,830

Post » Fri Feb 27, 2015 1:49 pm

The idea is there, just wrong implantation. With that for a test value in that case you would want to use a local var not global as it pertains only to that script. Trying to optimize my scripts as much as I possibly can, working on a massive game.

A expression refference method would be more beneficial & what I'm trying to ask for as it would mean any independent but mathmatically connected value between two instances of the same object type would need a new value created just for the connection, just to be constantly called, never mind if I want to constantly call the function.

If it is impossible with c2 then, yeah I will have to do it basically the same.
Need custom controls, video & sound options, and a PC like menu system with screenshot manager?
Image
B
20
S
4
G
2
Posts: 36
Reputation: 2,431

Post » Fri Feb 27, 2015 2:05 pm

hmm

if a score takes place, have it update a separate var, in a unique instance or global.
For instance a sprite named player1 with a instance var called score. Or a global var dedicated to the player 1's score.

Same goes for player 2 and others


Then, use

event
system, compare 2 values
(player1.score + player2.score+player3.score)
>
50
action
do something
Who dares wins
B
53
S
13
G
11
Posts: 1,758
Reputation: 13,830


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, hielo777, keeno79, smlyldz and 13 guests