Forum Topic: AS2 Coding Help

(71 views • 5 replies)

This topic is 1 page long.

<< < > >>
Shouting

colintso

Reply To Post Reply & Quote

Posted at: 9/16/08 05:06 AM

colintso FAB LEVEL 05

Sign-Up: 08/22/08

Posts: 42

I have this code which works like a conversation...the mcs is the dialogue. Can someone help me make this code more efficient? The code kinda puts your cpu usage up to 100%...

talk = 1
_root.attachMovie("empty", "empty", _root.getNextHighestDepth(), {_x:150, _y:200});
empty.onEnterFrame = function() {
if (Key.isDown(Key.SPACE)){
	talk += 1
}
if (talk == 1) {
	talk1 = _root.attachMovie("part_1_story_1", "part_1_story_1"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 2) {
	talk1.removeMovieClip();
	talk2 = _root.attachMovie("part_1_story_2", "part_1_story_2"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 3) {
	talk2.removeMovieClip();
	talk3 = _root.attachMovie("part_1_story_3", "part_1_story_3"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 4) {
	talk3.removeMovieClip();
	talk4 = _root.attachMovie("part_1_story_4", "part_1_story_4"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 5) {
	talk4.removeMovieClip();
	talk5 = _root.attachMovie("part_1_story_5", "part_1_story_5"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 6) {
	talk5.removeMovieClip();
	talk6 = _root.attachMovie("part_1_story_6", "part_1_story_6"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 7) {
	talk6.removeMovieClip();
	talk7 = _root.attachMovie("part_1_story_7", "part_1_story_7"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 8) {
	talk7.removeMovieClip();
	talk8 = _root.attachMovie("part_1_story_8", "part_1_story_8"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 9){
	gotoAndPlay (2)
}
trace (talk)
}

None

colintso

Reply To Post Reply & Quote

Posted at: 9/16/08 06:01 AM

colintso FAB LEVEL 05

Sign-Up: 08/22/08

Posts: 42

uh...hello?


None

SunderEX

Reply To Post Reply & Quote

Posted at: 9/16/08 06:38 AM

SunderEX LIGHT LEVEL 09

Sign-Up: 04/02/03

Posts: 82

You're attaching movies without removing them. That's not good practise, as it means you'll end up with just loads of movies crowding on top of each other.

A code efficient way of implementing it is to have all your talk text in an array. i.e.

var talkArray = new Array();
talkArray[0] = "0 text";
talkArray[1] = "1 text"
.....
talkArray[10] = "10 text".

And then use a dynamic text field, filling the text value with what you want.

myTextField.text = talkArray[talk];


None

SunderEX

Reply To Post Reply & Quote

Posted at: 9/16/08 06:40 AM

SunderEX LIGHT LEVEL 09

Sign-Up: 04/02/03

Posts: 82

Also trace() statements are very CPU intensive, if you have one pinging every frame it will slow down your player.


None

CyberXR

Reply To Post Reply & Quote

Posted at: 9/16/08 06:48 AM

CyberXR LIGHT LEVEL 09

Sign-Up: 08/22/08

Posts: 176

if (talk == 2) {
talk1.removeMovieClip();
talk2 = _root.attachMovie("part_1_story_2", "part_1_story_2"+_root.getNextHighestDep th(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 3) {
talk2.removeMovieClip();
talk3 = _root.attachMovie("part_1_story_3", "part_1_story_3"+_root.getNextHighestDep th(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 4) {
talk3.removeMovieClip();
talk4 = _root.attachMovie("part_1_story_4", "part_1_story_4"+_root.getNextHighestDep th(), _root.getNextHighestDepth(), {_x:494.9, _y:672.8});
}
if (talk == 5) {
talk4.removeMovieClip();
talk5 = _root.attachMovie("part_1_story_5", "part_1_story_5"+_root.getNextHighestDep th(),
}
trace (talk)
}

Ohh my fuck! Just chill man. Just create a MovieClip (named talkwindow) which follows your character all the time. When you talk to somebody this movieclip will gotoAndStop different frames. Thats how I did my Konga Game. Check it out

Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232


None

dragonjet

Reply To Post Reply & Quote

Posted at: 9/16/08 08:34 AM

dragonjet LIGHT LEVEL 20

Sign-Up: 12/02/05

Posts: 675

At 9/16/08 06:38 AM, SunderEX wrote: A code efficient way of implementing it is to have all your talk text in an array. i.e.
var talkArray = new Array();
talkArray[0] = "0 text";
talkArray[1] = "1 text"
talkArray[10] = "10 text".

this is the best recommended option: ARRAYS

Sig


All times are Eastern Standard Time (GMT -5) | Current Time: 08:28 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!