Forum Topic: In Game Achievements

(188 views • 10 replies)

This topic is 1 page long.

<< < > >>
Angry

Rabjab

Reply To Post Reply & Quote

Posted at: 4/21/09 02:31 PM

Rabjab EVIL LEVEL 07

Sign-Up: 06/23/08

Posts: 89

Ok, so I have been wondering recently, if I could make Achievements for a game in flash. I started by trying to make a code that basically shows text when you do something. Here is the code I made;

onClipEvent(load){
	var achievement1 = 0;
	var achievement2 = 0;
	var achievement3 = 0;
	var achievement4 = 0;
	var achievement5 = 0;
}
onClipEvent(enterFrame){
	if(this.hitTest(_root.box)){
		_root.achievement1 = 1
	}
}
onClipEvent(enterFrame){
	if(achievement1 = 1){
		trace ("Achievement1 Unlocked!");
	}
}

The problem is that the text appears even when you don't do anything, the trace says 'Achievement1 Unlocked!' Over and over.

I am not yet very good at creating my own actionscript codes, and would like a point in the right direction and an explanation on how to make this work.

Details: I use AS2 and Flash player 8

~Rabjab

The High And Mighty Rabjab
Rabjab.Newgrounds.com

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 4/21/09 02:38 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

1. Use arrays

2. You only need 1 enterFrame event

3. Where you have if(achievement1 = 1){ it should say if(achievement1 == 1){.

== is used for comparison.
= is used for assignment.

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

henke37

Reply To Post Reply & Quote

Posted at: 4/21/09 02:40 PM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,607

What we have here is a clear lack of logic. Do not use more than one enterframe handler.
You need to run the code only once, when the condition first is true. Add a condition that the event hasn't already happened.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


Mad as Hell

Rabjab

Reply To Post Reply & Quote

Posted at: 4/21/09 02:44 PM

Rabjab EVIL LEVEL 07

Sign-Up: 06/23/08

Posts: 89

1) Don't know what an array is. (Can you please explain?)

2) What ya mean? then it doesn't make sense... (Please explain)

3) When I do that, it doesn't do anything at all!

PLEASE EXPLAIN

The High And Mighty Rabjab
Rabjab.Newgrounds.com

BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 4/21/09 02:51 PM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

At 4/21/09 02:31 PM, Rabjab wrote: onClipEvent(enterFrame){
if(achievement1 = 1){
trace ("Achievement1 Unlocked!");
}
}

Every point that's been made still stands, but more pressing is the fact that you've got an assignment instead of a comparison. Use:

if(achievement1 == 1){...

Which isn't great in itself, since it'll still trace over and over once you get achievement1. Instead, run a check when you get the achievement and do whatever then:

if(whatever event you want to count as an achievement){
  if(!achievement1 == 0){
    achievement1 = 1;
    trace("ACHIEVEMENT!");
  };
};
BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 4/21/09 02:52 PM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

Ignore my first point. I completely failed to read UF's post past 'use arrays'.

BBS Signature

Angry

Rabjab

Reply To Post Reply & Quote

Posted at: 4/21/09 03:05 PM

Rabjab EVIL LEVEL 07

Sign-Up: 06/23/08

Posts: 89

Paranoia, Yeh thanks for the explanation and all but it's not working. I don't know why and if people are going to get pissed off with me then don't bother. I will try a different approach.

The High And Mighty Rabjab
Rabjab.Newgrounds.com

BBS Signature

None

mayoarm11

Reply To Post Reply & Quote

Posted at: 4/21/09 03:11 PM

mayoarm11 NEUTRAL LEVEL 17

Sign-Up: 06/13/07

Posts: 1,013

your achievement variables are local - they are on your MC

you don't access them with _root.achievement1, you just say achievement1 or this.achievement1

Awesome turret game in the making, featuring 85 uniqe turrets: News post

BBS Signature

Angry

Rabjab

Reply To Post Reply & Quote

Posted at: 4/21/09 03:21 PM

Rabjab EVIL LEVEL 07

Sign-Up: 06/23/08

Posts: 89

Still not working

The High And Mighty Rabjab
Rabjab.Newgrounds.com

BBS Signature

None

Shinki

Reply To Post Reply & Quote

Posted at: 4/21/09 03:30 PM

Shinki DARK LEVEL 10

Sign-Up: 02/14/05

Posts: 1,571

Learn to program, then make games, THEN add achievements.

You've come here with some code that doesn't do what it's supposed to, that's fair enough. But if you don't come here with enough knowledge of what you've already made and what you are using to make it (ie. Flash) to comprehend the responses you get, what's the point?

If a picture is worth a thousand words, a game is worth a play.

BBS Signature

None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 4/21/09 03:50 PM

Afro-Ninja EVIL LEVEL 38

Sign-Up: 03/02/02

Posts: 13,463

you need a better understanding of how variables and their scopes work

http://www.kirupa.com/developer/actionsc ript/tricks/scope.htm

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 08:25 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!