  | | | .js switch weirdness | .js switch weirdness 2004-12-17 - By Matthias Worch
Back I'm seeing weird behavior in a jscript I wrote yesterday, but I can't reproduce the problem in smaller test scripts. Maybe somebody has time to dig through this little thing and tell me why the switch statement at the end doesn't work? The script works anyway, but it irks me like hell ;)
//============================================================================== // toggleSelMode.js // Matthias Worch - http://www.langsuyar.com // Toggles between Point Select, Raycast Edge Select and Raycast Poly Select // tools for speedy modelling. Bind to Tab or similar key :) //==============================================================================
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- // We're keeping track of the last mode in a blob that attaches to the scene // root. Return blob's value (or create one if it doesn't exist)
function getCurrentSelMode() { var e = new Enumerator( ActiveSceneRoot.Properties ); var item; var currentSelMode; for( null; !e.atEnd(); e.moveNext() ) { item = e.item(); if( item.Type == "UserDataBlob" ) if( item.Name == "currentSelMode" ) { // cache and return the current mode, advance the index currentSelMode = item.Value; advanceSelMode( item ); return currentSelMode; } } // Blob doesn't exist yet! var Blob = ActiveSceneRoot.AddProperty( "UserDataBlob", false, "currentSelMode" ); Blob.Value = "0"; advanceSelMode( Blob ); return 0; }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- // Update blob's data with the next selection mode function advanceSelMode( item ) { item.Value++; if( item.Value >= 3 ) item.Value = 0; return; }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- // toggle mode function toggleSelMode( value ) { logMessage( value );
// this if/else works if( value == 0 ) { ActivateVertexSelTool(null); return; } else if( value == 1 ) { ActivateRaycastEdgeSelTool(null); return; } else if( value == 2 ) { ActivateRaycastPolySelTool(null); return; }
// the switch version of this doesn't work /* switch( value ) { case 0: ActivateVertexSelTool(null); break; case 1: ActivateRaycastEdgeSelTool(null); break; case 2: ActivateRaycastPolySelTool(null); break; Default: break; } */ }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- // main()
toggleSelMode( getCurrentSelMode() );
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |