Incrementing array index error

You think you've found a bug? Please report it here.

Moderators: Lapo, Bax

Post Reply
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Incrementing array index error

Post by Virusescu »

So.
I've got the following setup
tc is an array of objects. Each object has a num property.
cc is another array defined earlyer as
cc = [0,0,0,0,0,0,0];
with a length == the max tc[x].num value

Code: Select all

for (var x = 0; x < tc.length; x ++)
   {
	cc [tc [x].num] ++;
	
   }
The previous code yelds this error
SFS Console says
+---------------------[ Zones & Rooms ]----------------------+

DB Manager Activated ( org.gjt.mm.mysql.Driver )
Zone: TexasHoldemUp

Saloon (id: 1, max: 4000, pass:N)
Ch Room One (id: 2, max: 12, pass:N)
Exception in thread "SmartFoxServer" java.lang.VerifyError: (class: org/mozilla/
javascript/gen/c1, method: _c84 signature: (Lorg/mozilla/javascript/gen/c1;Lorg/
mozilla/javascript/Context;Lorg/mozilla/javascript/Scriptable;Lorg/mozilla/javas
cript/Scriptable;Ljava/lang/Object;D[Ljava/lang/Object;)Ljava/lang/Object;)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.mozilla.javascript.optimizer.Codegen.createScriptObject(Codegen.j
ava:81)
at org.mozilla.javascript.Context.compileImpl(Context.java:2232)
at org.mozilla.javascript.Context.compileReader(Context.java:1246)
at it.gotoandplay.smartfoxserver.extensions.JavascriptExtension.loadScri
pt(JavascriptExtension.java:303)
at it.gotoandplay.smartfoxserver.extensions.JavascriptExtension.setScrip
tFile(JavascriptExtension.java:107)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.loadExtens
ion(ExtensionHandler.java:129)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.createExte
nsion(ExtensionHandler.java:166)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.parse_Exte
nsions(ExtensionHandler.java:620)
at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(SmartFoxServer
.java:1756)
at it.gotoandplay.smartfoxserver.lib.ConfigReader.parse_Zones(ConfigRead
er.java:584)
at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigR
eader.java:284)
at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFo
xServer.java:309)
at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:
558)
I've tested and find out that the folowing code works ok. I hope it's incrementing the value as I haven't tested it throughly

Code: Select all

for (var x = 0; x < tc.length; x ++)
   {
        cc [tc [x].num] = cc [tc [x].num] +1;
   }
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I would suggest to unroll the expression into a simpler one, which also would help in making the code more readable

Code: Select all

for (var x = 0; x < tc.length; x ++)
{
   var id = tc [x].num 
   cc [id]++
}
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply