Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ShawnSwander

I was trying to make a narration script so the player can see "The orc hits you." at the bottom of his screen. I wanted to show the last 4 messages at one time and possibly allow the player to look back to see 30-50 messages in a log if they want. To do this I set up and object and an array to push the objects into.

So I set up some variables like this
servermessage: {"color1":"yellow", "color2":"white", "message1":"", "message2":""},
   servermessagelist: new Array(),

and when I use this command multiple times with different data
ig.game.servermessagelist.push(ig.game.servermessage)

it overwrites the entire array with copies of that data... any idea why or what I can do about it.

1 decade ago by techtech

I don't think that should happen.

Where did you set up that servermessagelist variable? I'm expecting it to probably be inside your game init() function inside main.js, is that correct?

Also, can you show an example of how you put "The orc hits you" (or whatever) into servermessage? If you are setting servermessagelist to "new Array()" every time you set servermessage, as implied above, then that is wrong. The "new Array()" blanks out the servermessagelist.

1 decade ago by paulh

.array.push [ ] not ()?

1 decade ago by jswart

Quote from paulh
.array.push [ ] not ()?


.push() is a method. And needs the ' () 's.

I have to agree with techtech. I think the array is being initialized in such a way that it is getting overridden. It is also better to create arrays like this:

var myArray = [];

1 decade ago by ShawnSwander

@all
No I figured it out.
Push was pushing the object reference not the object. Thus when the push happened effectively all elements were changed. I fixed it by specifying the entire object every-time I pushed.
i.e.
here = "here"
object.push({"settings":here})
Page 1 of 1
« first « previous next › last »