How do I use a function properly?

Get help using Construct 2

Post » Thu Mar 10, 2016 9:50 am

Hello,

I have a problem using the function.

For example I have:

1. "if object1 overlaps with object 2"-> "object 1 set invisible"

2. "if object1 overlaps with object 2"-> call functionx

functionx->"object 1 set invisible"

Case 1: works ok only object1 is invisible
Case 2 : all objects are invisible.

Real case scenarios are more complex but how shall I use the function properly in this case?
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Thu Mar 10, 2016 10:33 am

Message: Ken95 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
https://www.youtube.com/watch?v=OZXudAF8eh4
B
9
S
1
Posts: 26
Reputation: 479

Post » Thu Mar 10, 2016 10:48 am

This video is useless .

12:30 when he touches an enemy all enemies are stopped. He even says all the enemies.

But NO you want when you touch an enemy only that enemy to stop.....
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Thu Mar 10, 2016 12:17 pm

Message: Ken95 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
It is because he only used a single sprite. try making individual sprites for different objects. Here's a sample capx i made


https://drive.google.com/file/d/0B6Kon9NMcnGGRmY3MkthaF9uQWs/view?usp=sharing
B
9
S
1
Posts: 26
Reputation: 479

Post » Thu Mar 10, 2016 12:27 pm

paala wrote:
I have a problem using the function.

For example I have:

. "if object1 overlaps with object 2"-> call functionx

functionx->"object 1 set invisible"

.. all objects are invisible.


add object1 IID to function parameter...

functionx->
pick object1 by comparison IID=function parameter->object 1 set invisible
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Thu Mar 10, 2016 12:44 pm

thanks. using object IID should solve the issue
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Thu Mar 10, 2016 4:17 pm

In the event calling the function you have a condition that makes a list of all object1 that overlap object 2.
In the function you have an action that picks all the object1, because there is no condition limiting the picklist.

See it that way. You have always a 'picklist'. The picked objects stay in that list until you make another list.

Pick conditions are filters to shorten the picklist, they make a list, they do not pick. Unless there is only one object in the resulting list. But even then you should not see it that way. The actions are the pickers, they pick objects from the pre-filterd list.

The condition 'if object1 overlaps with object 2' makes a picklist of all instances of object1 and all instances of object2 who overlap. The action 'object 1 set invisible' takes all object1 instances in that picklist and makes them invisible.

You could now think: no pick condition means no new picklist. And that is exactly where things go wrong.

If you make a blanco event, followed by an action 'object 1 set invisible', then there was no filtering. The picklist contains all the objects. Every and each one. The action picks from that list all the object 1 instances.

Tip: Make a variable object1picked and a variable object2picked. Set those in an action to object1.pickedcount and object2.pickedcount right after a pick condition. Monitor those variables to understand what is gooing on. Loop true them with object(loopindex).
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Mar 11, 2016 8:21 am

Using object UID not IID is the correct answer to the problem
B
33
S
8
G
4
Posts: 155
Reputation: 3,752


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 28 guests