Two More (Hopefully Final) Coding Questions

A place for tutorials on how to get the most out of Flash

Two More (Hopefully Final) Coding Questions

Postby SteelSaurus » Mon Jul 01, 2013 4:20 pm

[[Repost of elsewhere because I don't know where to ask.]]

I've got nearly all of the hurdles for the first stage done, I'm at a bit of an impasse when it comes to figuring out Energy because it doesn't really have much use in spectator matches. I have it linked to how the Crowd will work (which I almost have figured out) and only really deals with special moves such healing, signatures, and finishers.

Right now, the spanner in the works is figuring out how to get an image or movie clip to appear when a criteria is met, and how to disappear when it's not. I'm trying to figure it out but I keep getting errors and/or the program freezes.

Problem One
Is there anyone familiar with ActionScript 1 or 2 who knows how to do this; if (Character = 1) {Image = "Sonya"} or, if (Character = 2) {show movie clip = "Beverly"} etc.
Any takers?


On a positive note, the game is now technically playable, though it only allows you to pick which two characters will fight against one another then lets you go move by move until time runs out or somebody wins.

I have a few other things I can do such as finishing the Crowd, Energy, Flavor Text (Rivalries are done, I'll try at coming up with a generic Intro page as well as flesh out some of the Hits and Misses), and maybe work on a Match Card that would show who's facing who beforehand (a Results Card and Score Card are inconceivable at the moment), but after that, I'm at the end of my tether.

Problem Two
Speaking of flavor text, is it possible to add paragraphs to a string? For example;
"Wow, this tastes good. I know, I made it myself."
Seen as;
Wow, this tastes good.
I know, I made it myself.



And just because, here's the game so far. (Looking good!!!)
Attachments
Click to Play
(Javascript Required)

New Code.swf [ 176.72 KiB | Viewed 2279 times ]

I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Two More (Hopefully Final) Coding Questions

Postby IrrelevantComment » Mon Jul 01, 2013 8:16 pm

Problem one:
Several methods, I'll give a brief overview. I would put the Sonya, Beverly etc movieclips as frames of a container movieclip with the frames being appropriately labelled. Then you can do something like:
Code: Select All Code
if(Character == 1)
     container.gotoAndStop("Sonya");
else if(Character == 2)
     container.gotoAndStop("Beverly");

However, I'm all about the arrays:
Code: Select All Code
var characters : Array = new Array("Sonya", "Beverly", etc);
...
container.gotoAndStop(characters[Character]);


Problem 2:
Try "Wow, this tastes good.\rI know, I made it myself." if '\r' doesn't work, try '\n' and if not, maybe text = "Wow, this tastes good." + newline + "I know, I made it myself.";
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Two More (Hopefully Final) Coding Questions

Postby KaTsuO_O » Tue Jul 02, 2013 3:27 am

For problem one, you could go with IrrelevantComment's suggestion. But a more simple way of doing it is just to write,

container.gotoAndStop(Character);

Let's say the first frame of the container doesn't show any character, in that case you can just add,

container.gotoAndStop(Character + 1);
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Two More (Hopefully Final) Coding Questions

Postby SteelSaurus » Tue Jul 02, 2013 2:50 pm

I lost the original thing that I was going to post, but to let you know, neither of these worked for me. I copied Irrelevant's coding word for word and it does abjectly nothing. Either the image scrolls through frames uncontrollably (I haven't touched anything yet it does this from loading, changing the number does nothing) or if I add a stop code to each from it get's stuck on the first and remains there even though the number changes.

However, what's a container? Is the MovieClip supposed to be named container (because I did), and each frame in the clip labeled as "Sonya" or "Beverly".
Attachments
Click to Play
(Javascript Required)

Offscreen Assistant.swf [ 231.34 KiB | Viewed 2224 times ]

I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Two More (Hopefully Final) Coding Questions

Postby IrrelevantComment » Tue Jul 02, 2013 7:52 pm

The codes me and Katsu posted needs to be called either every frame or preferably every time Character changes. You need a stop() on the first frame of the MovieClip to stop it cycling through
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Two More (Hopefully Final) Coding Questions

Postby SteelSaurus » Tue Jul 02, 2013 10:55 pm

It is. Or I did. That's what you see in the .swf above.
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Two More (Hopefully Final) Coding Questions

Postby IrrelevantComment » Tue Jul 02, 2013 11:06 pm

can you send the source file for that swf above?
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Two More (Hopefully Final) Coding Questions

Postby KaTsuO_O » Wed Jul 03, 2013 4:58 am

You need to give the symbol which should contain the characters, an instance name. To do that, click on the symbol on stage and open properties, at the top there should be a box where you can enter it. The instance name is the name that the program uses when it communicates with symbols on the stage, not the name you gave the symbol when you created it. That way you can have multiple of the same symbols on stage, but still being able to do things independently with each.

The code that you have placed on the first frame will only be checked once, meaning that even if you click the buttons and change data, nothing will change. You either need to place the code in the button, so that once you click on it, it updates. Or you can make it so that it always check.

So it would look something like this with the current code,

stop();

Colors = 0;
Character = 0;

onEnterFrame = function () {

if (Colors == 1) {
Colorized.gotoAndStop("Red");
} else if (Colors == 2) {
Colorized.gotoAndStop("Blue");
} else {
Colorized.gotoAndStop("Yellow");
}

if (Character == 1) {
container.gotoAndStop("Sonya");
} else if (Character == 2) {
container.gotoAndStop("Beverly");
}

}

onEnterFrame = function () makes it so that it always run that piece of code, so as soon as a variable chance, it does what it is supposed to do. The variables is not included, because they should only be set to the default value once. If you included them, then they would constantly be reset. I would write the code like this,

stop();

Colors = 0;
Character = 0;

onEnterFrame = function () {

container.gotoAndStop(Character);

Colorized.gotoAndStop(Colors);

}

It means that you don't have to update the code when you add more content, it is also a lot shorter.

Another thing, is the button code,

on (release) {
Colors = Colors + 1;
Character = Character + 1;
}

Instead it is more simple to write,

on (release) {
Colors += 1;
Character += 1;
}
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Two More (Hopefully Final) Coding Questions

Postby SteelSaurus » Wed Jul 03, 2013 3:14 pm

Yep. I tried naming the MovieClips their and their Instances. I put the code 'onEnterFrame' code on the timelines frames, on the button, on the MovieClip, on the frames of the Movie clip, and every combination thereof. None of it worked. As yet another unrelated side effect I've got the preliminary stages of a working health bar (this is getting hilariously frustrating; you try teach me something, it doesn't work, and in my niggling to get it to work via asinine methods I find something that does work... for something completely different).

When I head back (I only can an internet connection on the library computers) I'll give your coding another spin and try out the new button code. I unwittingly messed up something with the Select Character Option and I need to find out what.

Do you think that the coding that your giving me just doesn't work for ActionScript 1.0 and 2.0?
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Two More (Hopefully Final) Coding Questions

Postby KaTsuO_O » Thu Jul 04, 2013 9:20 am

Alright, I'll provide a step by step guide.

1. Create a new Actionscript 2.0 document.

2. Make a square and turn it in to a symbol.

3. Select it on the stage and open properties.
Symbol Instance Name.png

4. Enter the instance name you would like to give the symbol, it is case sensitive, so I recommend to only use lower case letters.

5. Go inside the symbol and add more frames, as well as change the color of the square on each frame.

6. Go back out from the symbol. Click on the frame on the main timeline, open the actions panel and enter this code:
Code: Select All Code
variable = 1;

onEnterFrame = function () {
square.gotoAndStop(variable);
}

"square" was the instance name I gave my symbol, replace it with the instance name you used.

7. Create a button and give it this code:
Code: Select All Code
on (release) {
variable += 1;
}


8. Go back in to the square symbol and insert one last frame. On that frame, add this code:
Code: Select All Code
_root.variable = 1;
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Two More (Hopefully Final) Coding Questions

Postby SteelSaurus » Fri Jul 05, 2013 2:26 pm

I was able to fiddle around with the last bit of info you sent me and was able to get it working. See here:
Click to Play
(Javascript Required)

New Code.swf [ 237.61 KiB | Viewed 2096 times ]


Thank you endlessly for your help.

All that's left now is adding a bit more flavor text, tidying up some designs (like the crowd's excitement level), and banging the kinks out of the coding (the scoreboard refuses to calculate properly). Once that's done I can get to work on the Sponsorship option to let you take control of the character. I'm still hesitant in trying to animate, though if I could learn all this coding in a week, who knows what can happen.
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users