Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 01:14:05 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)AS3/flashpunk question! (really dumb i'm sorry)
Pages: [1]
Print
Author Topic: AS3/flashpunk question! (really dumb i'm sorry)  (Read 669 times)
klopgeest
Level 0
*


View Profile
« on: May 10, 2015, 06:30:43 PM »

hi guys, i hope i'm posting this in the right place. i'm super new to programming in general and i keep getting stuck on dumb things like this.

i'll just dump the code before anything else (this is pretty much the entire WIntro class):

Code:
private var currentID:uint = 0;

private var texts:Array =
[
"hello, traveler.",
"couldn't figure out typewriter text, i see?",
"it's understandable.",
"you'll get there.",
"probably."
]

public function WIntro()
{
super();
}

override public function begin():void
{
Text.font = "PStart";
Text.size = 8;
var introText:Text = new Text(texts[currentID]);
var textEntity:Entity = new Entity(0, 0, introText);
textEntity.x = 32;
textEntity.y = 64;
add(textEntity);
}

override public function update():void
{
super.update();

if (Input.check(Key.ANY))
{
if (currentID != 4)
{
currentID++;
}
else
{
FP.world = new WGame();
}
}
}

basically all i want to do is have the text skip to the next string when a button is pressed. i also wanted to add a typewriter effect, but first things first i guess?
Logged
Cheezmeister
Level 3
***



View Profile
« Reply #1 on: May 10, 2015, 08:47:29 PM »

I'm not good with AS3 or FP, but based on what you've posted, your problem is that you're changing the variable after you've already used it, and not reading it again.

Code:
// Game starts
var introText:Text = new Text(texts[currentID]); // currentID is 0
var textEntity:Entity = new Entity(0, 0, introText);
add(textEntity); // "hello, traveler."
// Later
currentID++; // currentID is 1
// textEntity still hasn't changed
// introText still hasn't changed

That's like...telling everyone the party is at 7, then later changing your mind but not telling anyone. They're gonna show up at 7. What you need to do then is modify the text on introText, or new up another one and stick it on textEntity.

HTH.
Logged

෴Me෴ @chzmstr | www.luchenlabs.com ቒMadeቓ RA | Nextris | Chromathud   ᙍMakingᙌCheezus II (Devlog)
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic