1 decade ago by faytmye
Hi all,
I'm a beginner to ImpactJS and i've been experimenting with the engine for a bit now but I'm running into troubles with something that should be simple.
Basically I just want to print an array to a new line for each entry that exists within in. I just can't understand why it's not working but I'm sure it's something silly that I missed or forgot about.
This is the error that I am getting:
I'm a beginner to ImpactJS and i've been experimenting with the engine for a bit now but I'm running into troubles with something that should be simple.
Basically I just want to print an array to a new line for each entry that exists within in. I just can't understand why it's not working but I'm sure it's something silly that I missed or forgot about.
This is the error that I am getting:
1 decade ago by Logan
I noticed that in your array
try that? See what happens?
hOne: [ fName="Bruce", lName="Wayne", title="The Dark Knight", hp=100, mp=50 //The comma behind 50 should be removed. ],
try that? See what happens?
1 decade ago by tuttlegames
I'm not a JS expert but it seems like you're drawing a string and then a line break at the same position, over and over. Naturally, they will overlap and the line breaks will be essentially useless.
I'd do something like:
Maybe you can also do something like consolidating all the values you want into one big string, delimited by a "\n", and draw just that one string once.
I'd do something like:
for (i=0 ; i < hero.hOne.length ; i++) { this.font.draw(hOne[i], 20, 20*i); }
Maybe you can also do something like consolidating all the values you want into one big string, delimited by a "\n", and draw just that one string once.
1 decade ago by faytmye
This fixed the problem, thanks so much :)
20*i
1 decade ago by drhayes
tuttlegames is right, that'll work much better than iterating through the array.
On that note: your syntax is wrong. You don't want an array, you want an object:
You can iterate through those properties using a loop like you have, but that output that looks like JS code likely is JS code from the object&
Change your for loop to look like this, maybe:
That'll prevent code from showing up like you have in the screenshot.
On that note: your syntax is wrong. You don't want an array, you want an object:
hOne: { fName: 'Bruce', lName: 'Wayne', // etc.. }
You can iterate through those properties using a loop like you have, but that output that looks like JS code likely is JS code from the object&
039;s prototype. That's because an expression like #hOne['whatever']
will pull not just fields, like you've defined, but also methods on the object or its prototype (kinda like its parent, but just roll with me here).Change your for loop to look like this, maybe:
var i =1; for (var j in hero.hOne) { if (hero.hOne.hasOwnProperty(j)) { ig.font.draw(hOne[j], 20, 20 * i); i++; } }
That'll prevent code from showing up like you have in the screenshot.
Page 1 of 1
« first
« previous
next ›
last »