Currently I'm trying to have two instances of an auction run simultaneously, but it seems when I'm creating a new object it's the exact same object as the one before it.
The Code:
Here is the code that creates the new object:
AuctionSell._state = new auctionGen();
AuctionSell._state.init(i);
auctions.push(AuctionSell._state);
To note, auctionGen() is a function that returns an object containing all the variables and logic surrounding the auction itself.
function auctionGen()
{
return {
//code
}
}
^ this is just a blank template to show how the object is actually being created.
Updates the auctions array:
update : function(dt)
{
if(auctions.length > 0)
{
for(var i = 0; i < auctions.length; ++i)
{
if(!auctions[i]._expired)
{
auctions[i].update(dt);
}
else
{
auctions.splice(i, 1);
}
}
}
}
As you can see I create the new object then push it into an array that will contain my auctions. This happens in the auction's init function which only gets called when a new auction is to be created. I've checked the data of both auction states and they contain the different vehicles that are up for auction, however it appears as if creating the new one halts the old one.
Example:
If I run one auction alone - depending on the car - the final bid will always be higher than it's actual value. However, if I run these auctions simultaneously it is guaranteed to be under value.
I just ran two auctions simultaneously, the price of the first vehicle was $18000 but the Auction ended with a bid of $6370. The second car was valued at $57,000 and the Auction ended at $46428.
All of the bids are done by AI, and they are programmed to always stop bidding at a certain point above the value of the vehicle. This issue only appears when running two or more auctions at one time.
The Question
Is there another method in which I should be creating these objects to make them truly new objects? As of right now they seem to interfere with each other.
Edit:
After changing the update call to be the following:
update : function(dt)
{
var i;
if(auctions.length > 0)
{
i = 0;
while(i < auctions.length)
{
if(!auctions[i]._expired)
{
auctions[i].update(dt);
++i;
}
else
{
auctions.splice(i, 1);
}
}
}
}
and fixing my ai array to no longer be global, it seems as though the issue now only occurs on the second vehicle auction. The bidding for the $57,000 vehicle stopped at $17,198 where my $12,000 vehicle stopped at $23,947 (intended behaviour)
newwill almost certainly be unnecessary here, unless you usethisinside yourauctionGen()constructor, since you're returning fromauctionGen().function auctionGen(){}should returnthisafter initialization