Casino Machine using a panel and Graphical Scripting
From C4 Engine Wiki
Here is the rough beginnings of a casino machine. It uses C4's Graphical Scripting Language and a panel. The script assumes there are three textures called pic1, pic2 and pic3. These can be downloaded here or you can create them yourself. You can easily increase the number of types of items in the machine or the number of columns except that it would mean you would probably win less. At the moment you have a 1 in 9 chance of winning, and it pays out a very generous 8 times (40 credits) the amount you put in (5 credits). To make it more realistic the pay out amount should be reduced otherwise you'll win too much.
Contents |
Setting up the panel
- Go to the effects page and draw a panel in the world with a width twice its height
- Select the panel, use Ctrl-I, go to the Properties tab, assign the Interaction property
- Go to the Connectors tab and add one called SND1 and one called SND2 (for the sound effects)
- Go to the Controller tab, setup the cursor (mouse pointer) texture
- Set the interface width to double the interface height
- Go to "Edit Panel"
- Create three square textures in a row with the "Item identifiers" CEL1, CEL2 and CEL3
- Create some text that says Click Here To Play! and another saying Credits:
- Next to "Credits:" create some text with the "Item identifier" CRED and 100 as the text
- Select "Click Here To Play!" and click "Edit Script"
Basic Script
This script has no sound effects, use of credits or detection of wins. Fibers connect the method boxes. Use the hotkey "9" to go into draw fiber mode. The fiber colors can be changed by selecting them and using the Ctrl-F hotkey. When there is a boolean statement, the green fiber is used it the statement is true, and the red fiber is used if the statement is false. Black fibers are used whatever kind of boolean statement they come from.
For the {VariableName} = {Expression} methods, use the Evaluate Expression method.
For "Set Item Image", use the "Call Controller Function" method, set the "Target Node" to "Controller target" and the function to "Set Item Image". Set the "Target item identifier" to CelName in the right (input variables) column. Set "Panel item texture map name" to ImgName in the right (input variables) column.
For "ImgNum = Random Integer", the minimum value is 1 and the maximum value is the number of image kinds, which is 3.
For Delay, the time has been set to 0.2 seconds.
Basic Script Variables
- CelName - String
- CurrentCelNum - Integer
- ImageName - String
- ImageNum - Integer
Full Script
Added methods are yellowish.
Note that the script pauses until the sound effects have finished playing. If the script had branched off instead with the sound effects not leading to more script methods, there would be no pausing.
For "Set Item Text", use the "Call Controller Function" method, set the "Target Node" to "Controller target" and the function to "Set Item Text". Set the "Target item identifier" to CRED in the middle column. Set "Panel item text" to Credits in the right (input variables) column. Make sure the "Text combine mode" is "Replace" and "Max result length" to how many digits to use for Credits... e.g. 4.
Note that if you want to debug your script you can add a method in the "custom" tab called "Display Message". You can put variable names in the right column.
Full Script Variables
- CelName - String
- Credits - Integer, scope: Object (so it remembers its value), initial value: 100
- CurrentCelNum - Integer
- ImageName - String
- ImageNum - Integer
- MatchingImg - Boolean
- PreviousImgNum - Integer


