Component Script Sample 2 |
Top Previous Next |
Keypad.talk _______________________________________________________ // Script for Keypad 2.0 (advanced) // by Oscar (4 Jan 2004) // This is a more complex example than the Keypad 1.0 // Please note that you should look at tutorial that examines the lines // otherwise it may be too overwhelming
// First it asks for the secret access code which can be any length (unlike the 1.0) // and all necessary menus and connections are created by script. // This script runs automatically after you load the Component // You can bypass the script when you hold SHIFT
// Component access to the objects: // in order to know which objects belongs to the component // three array variables are filled up:menusInBlackBox, vmgsInBlackBox, moviesInBlackBox
// menusInBlackBox retuns the number of menus in box and // menusInBlackBox[1] returns what is the order number relative to project of the first menu in box // see this example below: /* print "Number of Menus in this Component: ",menusInBlackBox for menu=1 to menusInBlackBox print "Menu #",menu," in Component is a Menu #",menusInBlackBox[menu]," in a whole project" next menu */*/ // note, the number returned by vmgsInBlackBox[x] is in range 1...255, // while all Menu functions uses vmg in range 10001-10255 // that means you have to add 10000 or use function VMG(vmgsInBlackBox[x])
// Get The secret code from user // use only numbers 1-9 nCode=123 input "This is a keypad component that allows access by code.","The access code can be any lenght, but use only digits 1-9","","Secret Access Code",nCode,"","(c) Oscar 2004" // terminate script if pressed cancel if bCancelInput then end endif // some global font settings for the text object that will be created fontSize = 70 fontFace = "Arial" fontX = 317 fontY = 100 // now get the secret access sequence into array // we will simply divide it by 10 untill there is no more digits nNum = 1 nTempCode = nCode //***** nice and happy goto loop :-) ************ 10 nNewCode = INT(nTempCode/10) // get the digit codes[nNum] = nTempCode-nNewCode*10 // show it in output for debug trace codes[nNum] nNum=nNum+1 nTempCode = nNewCode // still something left - loop to label 10 if (nNewCode>0) then goto 10 endif //************ end of the goto loop *********************** // here we are, the digits are in the codes array, but in wrong dirrection: codes[1] is the last digit // remember that later !!!! nNumberOfDigits = nNum-1 // we have this many digits in our secret code // this determines the number of menus trace nNumberOfDigits // create a BAD 1 menu //******************************************** menu = MenuAdd(FALSE,"BAD 1",FALSE) // copy from the first in black box to the new created menu MenuCopy(menusInBlackBox[1], menu) // now link all objects from menusInBlackBox[1] to menu // how many objects in the menu nOb = ObjectGetCount(menusInBlackBox[1]) // link all from start to bad 1 for x=1 to nOb ObjectLinkToMenu(menusInBlackBox[1],x,menu) next x // put a star as text for user feedback stars = "*" object = ObjectAdd(menu,3,RGB(0,0,0),stars) ObjectSetPos(menu,object,fontX,fontY) ObjectSetFont(menu,object,fontFace,fontSize) ObjectSetShadow(menu,object,0,0) MenuPlaceNear(menu, menusInBlackBox[1], 0, 4) MenuGroupWith(menu, menusInBlackBox[1],0) // remeber the last good and bad menu prevbad = menu prevgood = menusInBlackBox[1] // counter for codes array codecounter = nNumberOfDigits // now we need nNumberOfDigits-1 menu pairs //***************************************************** for y=1 to nNumberOfDigits-1 name = "GOOD "+CHR(48+y) menuGood = MenuAdd(FALSE,name,FALSE) MenuCopy(menusInBlackBox[1], menuGood) // Place the box right of previous good and add it to the component MenuPlaceNear(menuGood, prevgood, 0, 2) MenuGroupWith(menuGood, prevgood,0) name = "BAD "+CHR(48+y+1) menuBad = MenuAdd(FALSE,name,FALSE) MenuCopy(menusInBlackBox[1], menuBad)
// Place the box right of previous bad and add it to the component MenuPlaceNear(menuBad, prevbad, 0, 2) MenuGroupWith(menuBad, prevbad,0)
// now link this good menu and previous bad menu to the bad menu for x=1 to nOb ObjectLinkToMenu(menuGood,x,menuBad) ObjectLinkToMenu(prevbad,x,menuBad) next x //link the object corresponding to the secret digit from last good menu to this good menu ObjectLinkToMenu(prevgood,codes[codecounter],menuGood)
// add the star so users see feedback how many keys he enterred // we defined the stars before loop trace stars // add text object object = ObjectAdd(menuGood,3,RGB(0,0,0),stars) ObjectSetPos(menuGood,object,fontX,fontY) ObjectSetFont(menuGood,object,fontFace,fontSize) ObjectSetShadow(menuGood,object,0,0) // the bad has one star more stars=stars+"*" object = ObjectAdd(menuBad,3,RGB(0,0,0),stars) ObjectSetPos(menuBad,object,fontX,fontY) ObjectSetFont(menuBad,object,fontFace,fontSize) ObjectSetShadow(menuBad,object,0,0) // because the array is in opposite order codecounter = codecounter-1 // now rememv=ber the previous bad and good prevbad = menuBad prevgood = menuGood next y // BAD end ******************************************************************** // the last bad menu doesn't link to anything - it is the dead end ACCESS DENIED for x=1 to nOb // since the ObjectDelete change the object order // we need to delete just the first object few times ObjectDelete(prevbad,1) next x // delete also the stars text, we will put access denied ObjectDelete(prevbad,1) object = ObjectAdd(prevbad,3,RGB(0,0,0),"WRONG CODE") ObjectSetPos(prevbad,object,fontX,fontY+5) ObjectSetFont(prevbad,object,fontFace,fontSize/3) ObjectSetShadow(prevbad,object,0,0) // link it to the start MenuEndLink(prevbad, menusInBlackBox[1]) // set timer to 1 sec before we go to the start MenuSetPBC(prevbad,1,0,0) // GOOD END ************************************************* // this is the last menu menuGood = MenuAdd(FALSE,"GOOD END",FALSE) MenuCopy(menusInBlackBox[1], menuGood) // right of last good menu MenuPlaceNear(menuGood, prevgood, 0, 2) // put it inside the Component MenuGroupWith(menuGood, prevgood,0) // delete all objects for x=1 to nOb // since the ObjectDelete change the object order // we need to delete just the first object few times ObjectDelete(menuGood,1) next x ObjectLinkToMenu(prevgood,codes[codecounter],menuGood) // it should be 1, since this is the last digit = first in the array) trace "Last Digit ",codecounter // put a ACCESS OK text object = ObjectAdd(menuGood,3,RGB(0,0,0),"ACCESS OK") ObjectSetPos(menuGood,object,fontX,fontY+5) ObjectSetFont(menuGood,object,fontFace,fontSize/3) ObjectSetShadow(menuGood,object,0,0) // set 2 sec timeout MenuSetPBC(menuGood,2,0,0) // set this menu to be an output object in connection MenuSetComponent(menuGood, FALSE, TRUE) // now you need to connect the GOOD END with any menu Created with DVD-lab Pro |