How to Make a Simple Instant Win Game
This sample demonstrates how to make a simple instant win game, where participants are given prizes according to the ordinal numbers of their messages.
Files
used in this sample are located in the folder:
C:\Program Files\CodeSegment\SMS Studio\Samples\InfoService\InstantWinGame
Upon receiving an incoming message, the script InstantWinGame.vbs checks the ordinal number of the message and informs the user if he won the prize. The script awards each
50th, 100th, 500th and 1,000th sender in each group of 1,000 messages.
The contents of the InstantWinGame.vbs file:
if WScript.Arguments.Count = 3 then
PipeName = WScript.Arguments(0)
MsgID = WScript.Arguments(1)
DataFileName = WScript.Arguments(2)
if PipeName <> "" then
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.OpenTextFile(DataFileName,1,true)
MsgCount = 0
if file.AtEndOfStream <> true then
MsgCountTxt = file.ReadLine()
if IsNumeric(MsgCountTxt) then
MsgCount = CInt(MsgCountTxt)
if MsgCount >= 1000 then
MsgCount = 0
end if
end if
end if
file.Close
MsgCount = MsgCount + 1
ReplyText = "Sorry, no prize for you."
if MsgCount = 50 then
ReplyText = "Congratulations, you have won the prize for 50."
elseif MsgCount = 100 then
ReplyText = "Congratulations, you have won the prize for 100."
elseif MsgCount = 500 then
ReplyText = "Congratulations, you have won the prize for 500."
elseif MsgCount = 1000 then
ReplyText = "Congratulations, you have won the prize for 1000."
end if
set file = fso.CreateTextFile(DataFileName,true)
file.WriteLine(MsgCount)
file.Close
set pipe = fso.CreateTextFile("\\.\pipe\" & PipeName)
pipe.WriteLine("ReplyToID:" & MsgID)
pipe.WriteLine("Body:" & ReplyText)
pipe.WriteLine("<Send>")
pipe.Close
WScript.Quit(0)
else
MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Instant Win Game Sample"
WScript.Quit(1)
end if
else
MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Instant Win Game Sample"
WScript.Quit(1)
end if
How to run this sample
- Click the New button on the main toolbar and select the Info service option in the New Service dialog.
- Click the Setup button on the main toolbar to display the Info Setup dialog.
- In the General tab of the Info Setup dialog click the Add button to display the Add Rule dialog.
- In the General tab of the Add Rule dialog enter the following parameters:
Name: Instant Win
Pattern: Win
Action: Execute external application
- In the Execute tab of the Add Rule dialog enter the following parameters:
External application: InstantWinGame.vbs - use the selection button ( ... ) to locate and select the external application.
Application parameters:
"%PipeName%" "%MsgID%" "InstantWinGameData.txt"
- Click the Add button to close the Add Rule dialog.
- In the Advanced tab of the Info Setup dialog enter the name of the pipe:
Pipe name: WinPipe
- Click the OK button to close the Info Setup dialog.
- Click the Start
button on the main toolbar to start the Info service.
- Use Tools / Receive Message option in the main menu to
display the Receive Message dialog. Fill in the
Text field with the text Win and click the Receive
button. The Info
service will receive this message and run the InstantWinGame.vbs
application which will inform the user if he won the prize by storing a reply in the Outbox.
Related topics
Named Pipe