Subtract a value based on a another value?

Get help using Construct 2

Post » Sun Feb 03, 2013 7:53 am

Hi,

I'm currently developing a game, where in the enemy upon bullet impact suffers a particular amount of damage. I added a power up which would increase the bullet's damage via Instance Variables.

Now, I want the bullets damage to be added upon the original damage.

How do I do so?!

I've tried:
Subtract from:
10 + (Bullet.DMG)

{10 here is the original damage, and Bullet.DMG is whatever gets increased)

Is this right?! 'Cuz it ain't working.

Thanks.
B
4
G
1
Posts: 33
Reputation: 564

Post » Sun Feb 03, 2013 8:10 am

Assuming that Bullet is the object you've picked in the collision event and DMG is the instance variable, then that should be correct yes, although the () around Bullet.DMG aren't necessary.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sun Feb 03, 2013 8:24 am

With any help request it helps posting a capx to answer accordingly to how you exactly did things so far.

theubie answer might be sufficient though (it depends, once again, on how you implemented your project so far).
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sun Feb 03, 2013 9:33 am

Umm,

In my game I made it as a global variable, for both the bullet and the enemy, whatever name but for example "BulletDamage" and "EnemyHealth" and when the bullet hits the enemy:

Bullet -> On collision with another object -> Enemy -> Subtract "BulletDamage" from "EnemyHealth".

And when you pick up a powerup, just make another event:

Player -> On collision with another object (powerup) -> Add 10 to "BulletDamage".

This way worked for me, hope it helped!
B
13
S
5
G
2
Posts: 64
Reputation: 3,012

Post » Sun Feb 03, 2013 12:07 pm

@Jonsterz:
Thank you, the Global Variable worked!!

Just one more thing, since I really don't want to make a new post for it:
How do I randomize a Instance Variable?

I have a "Cash drop" that I want to be random. So whenever the player picks it up, it'll be a random number anywhere from 0 - 10.

I tried random(0, 10) but then the "text object" I use to display it goes blank.

Global Variable again?!

Please help.
Thanks!!yodason452013-02-03 12:08:47
B
4
G
1
Posts: 33
Reputation: 564

Post » Sun Feb 03, 2013 4:05 pm

[QUOTE=yodason45] @Jonsterz:
Thank you, the Global Variable worked!!

Just one more thing, since I really don't want to make a new post for it:
How do I randomize a Instance Variable?

I have a "Cash drop" that I want to be random. So whenever the player picks it up, it'll be a random number anywhere from 0 - 10.

I tried random(0, 10) but then the "text object" I use to display it goes blank.

Global Variable again?!

Please help.
Thanks!![/QUOTE]

First, check that the text box is big enough to display the text, if it's not big enough, it will go blank.

Yeah, the random value works. Although I'm not quite sure you need to set the 0 value, I think it automatically sets that. Just have the amount of total cash you have, as a global variable.

Example:

Global Variable -> Cash.

Event: Player -> On collision with another object (the cash object)

Action: System -> Add to Cash ( And insert here, random(10) or random(0,10).

Hope this hepled, and glad my previous tip worked!
B
13
S
5
G
2
Posts: 64
Reputation: 3,012

Post » Mon Feb 04, 2013 6:40 am

@Jonsterz:
You were right, the text object wasn't big enough to display it.

But apparently it wasn't big enough because my figure is going into ".123456".
Eg. Upon collecting CASH, it goes to a random no. like "4" but with ".468828" added to it, making it "4.468828".

Why am I getting the decimal with the digits after. I don't want those.
Is there a way to just round up the number? Rather than it to show up something like this "4.2486224"?

Please help?!
Thanks!!
B
4
G
1
Posts: 33
Reputation: 564

Post » Mon Feb 04, 2013 7:06 am

Do it like this : round(random(0,10))
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Mon Feb 04, 2013 8:39 am

[QUOTE=vee41] Do it like this : round(random(0,10))[/QUOTE]

What he said.

Cheers!
B
13
S
5
G
2
Posts: 64
Reputation: 3,012


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests