Let the player carry a value (money) from a object

Get help using Construct 2

Post » Mon Apr 22, 2013 4:04 pm

As the topic say, I`m wondering how I let the player carry a value from a object after the player has picket it up. Like in my Alex The Kid - In The Miracle World remake, I want to carry 1 coin from a money-object.

I have tried to search the forum for a similar idea, but I only found
this tread: http://www.scirra.com/forum/picking-up-coins-and-scoring-points_topic53475.html, but that didn`t worked.


Heres my capx:
https://www.dropbox.com/s/sakwfsv3hwe7itz/AlexTheKidInTheMiracleWorldRemake2.capx
System:
ASUS rog G550JK - 12GB ram - Nvidia GeFroce 850 2GB
Constuct 2 personal
B
6
Posts: 28
Reputation: 781

Post » Mon Apr 22, 2013 4:24 pm

You could just use an instance variable on your money object, have the player sprite check the value stored in it and then add that number to whatever variable holds the users current money total in the same event that is used to have the player pick up the object.

For example:

On player collision with money object - add moneyobject.value to player.currentmoney

BluePhaze2013-04-22 16:27:08
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Mon Apr 22, 2013 5:05 pm

So, I have to add a value to the money-sprite?
And when the player collect the money-sprite the player-sprite need
to figure out what value that money-sprite contains?

Like as you said:


On player collision with money object
add moneyobject.value to player.currentmoney (Number which is money)

Correct me if I`m wrong :)


I also want to add that I want to have a text-box that shows how many moneys the player have picked up. Thanks for all your help so far!

Aasmund2013-04-22 18:22:08
System:
ASUS rog G550JK - 12GB ram - Nvidia GeFroce 850 2GB
Constuct 2 personal
B
6
Posts: 28
Reputation: 781

Post » Mon Apr 22, 2013 9:14 pm

add this as a second event to your "on pickup coin" code

set textbox.text = player.currentmoney

justifun2013-04-22 21:15:00
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Mon Apr 22, 2013 10:07 pm

I can`t figure out how to add

"moneyobject.value to player.currentmoney"
on the moneyobject. The . gives me a invalid-character when I
add the codeline to the instance variable.

@BluePhaze: Did you had a look at my capx?
System:
ASUS rog G550JK - 12GB ram - Nvidia GeFroce 850 2GB
Constuct 2 personal
B
6
Posts: 28
Reputation: 781

Post » Mon Apr 22, 2013 10:22 pm

Your money object needs to have an instance variable called value, and the player needs to have an instance variable called currentmoney.

Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Mon Apr 22, 2013 10:27 pm

@Aasmund I am at work right now, will have to wait till tonight. To get the . to work you need to first add instance variable to your money object, the same way you add behaviors. In the properties pain for your money object, click on add instance variable. Create one called value. On your character create an instance variable called currentMoney. Or just create a global variable called currentMoney. Then in your event when the player collides with the object just do the code like I have above, system add moneyObject.value to currentMoney. Then destroy the money object so you don't keep adding it over and over while the player is colliding with it.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Mon Apr 22, 2013 10:54 pm

Will try that to morrow. Have to get to bed, heading to work myself at 07:00 :)
System:
ASUS rog G550JK - 12GB ram - Nvidia GeFroce 850 2GB
Constuct 2 personal
B
6
Posts: 28
Reputation: 781


Return to How do I....?

Who is online

Users browsing this forum: SpartCrafter and 19 guests