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.
How to run this sample
Source code
The contents of the InstantWinGame.vbs file:
'-------------------------------------------------------------------------------------------------------------------------------
' This script demonstrates how to make a simple instant win game.
' WARNING: Error checking omitted for clarity.
'
' Use the following application parameters in the Info Rule dialog:
' "%PipeName%" "%MsgID%" "InstantWinGameData.txt"
'-------------------------------------------------------------------------------------------------------------------------------
if WScript.Arguments.Count = 3 then
' Collect arguments
PipeName = WScript.Arguments(0) ' Pipe name
MsgID = WScript.Arguments(1) ' Incoming message ID
DataFileName = WScript.Arguments(2) ' Data file name
if PipeName <> "" then ' Pipe name must be specified in the Info Setup dialog
' Create file system object
set fso = CreateObject("Scripting.FileSystemObject")
' Load the message count from the file
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 ' Reset counter to 0 when it reaches 1000
MsgCount = 0
end if
end if
end if
file.Close
' Give the prize for the 50th, 100th, 500th and 1000th message
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
' Save the message count to the file
set file = fso.CreateTextFile(DataFileName,true)
file.WriteLine(MsgCount)
file.Close
' Send the reply back to the user via the Info pipe
set pipe = fso.CreateTextFile("\\.\pipe\" & PipeName)
pipe.WriteLine("ReplyToID:" & MsgID)
pipe.WriteLine("Body:" & ReplyText)
pipe.WriteLine("<Send>")
pipe.Close
WScript.Quit(0) ' Success
else
MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Instant Win Game Sample"
WScript.Quit(1) ' Error
end if
else
MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Instant Win Game Sample"
WScript.Quit(1) ' Error
end if
'-------------------------------------------------------------------------------------------------------------------------------
' Copyright (c) 2002-2009 CodeSegment. All rights reserved. http://www.codesegment.com/
'-------------------------------------------------------------------------------------------------------------------------------
| Copyright © 2002-2010 CodeSegment. All rights reserved. |