Jump to content

Random and Global Variables


Recommended Posts

Hey,

I'm working on an AutoIt script which is like Sloganizer.net (i542)

Basically, I'm not sure on how to declare the possible answers and then randomly pick one. Once I have learnt, I will understand it, which means I won't ask for help on the matter again, in fact I can help on them :)

Here is what I have so far,

#include <GUIConstants.au3>

$sGui = GUICreate("Sloganizer.Net :: Secure_ICT AutoIt Version", 554, 338, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("logo.jpg", 0, 16, 553, 81, BitOR($SS_NOTIFY,$WS_GROUP))
$Text = GUICtrlCreateInput("Text", 72, 112, 385, 21)
$sloganize = GUICtrlCreateButton("Sloganize", 152, 144, 217, 25, 0)
$FinalText = GUICtrlCreateLabel("", 72, 192, 4, 4)
GUICtrlSetFont(-1, 36, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

Global $Answer
$Answer[0] = "<< " & $Text & " will be for you what you want it to be.>>"
$Answer[1] = "<< " & $Text & ", in touch with tomorrow.>>"

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sloganize
                        SloganizeTxt()
    EndSwitch
WEnd

Func SloganizeTxt()
    $SloganizeNow = GuiCtrlRead($Text)
    $Random = Random($Answer)
    GUICtrlSetData($Random)
EndFunc

The image is attached below.

Thankyou for helping in advance,

Secure

Edited by Secure_ICT
Link to comment
Share on other sites

Basically, I'm not sure on how to declare the possible answers and then randomly pick one.

One method would be to declare an array containing the possible answers, then use Random with the integer flag to pick an array element.

Untested:

$max_num_slogans=50
Dim $a[$max_num_slogans] + 1
$a[1] = 'foo'
$a[2] = 'bar'
;etc

$i = Rand(1,$max_num_slogans,1)
consolewrite($a[$i])

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Hey,

I'm working on an AutoIt script which is like Sloganizer.net (i542)

Basically, I'm not sure on how to declare the possible answers and then randomly pick one. Once I have learnt, I will understand it, which means I won't ask for help on the matter again, in fact I can help on them :)

Here is what I have so far,

#include <GUIConstants.au3>

$sGui = GUICreate("Sloganizer.Net :: Secure_ICT AutoIt Version", 554, 338, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("logo.jpg", 0, 16, 553, 81, BitOR($SS_NOTIFY,$WS_GROUP))
$Text = GUICtrlCreateInput("Text", 72, 112, 385, 21)
$sloganize = GUICtrlCreateButton("Sloganize", 152, 144, 217, 25, 0)
$FinalText = GUICtrlCreateLabel("", 72, 192, 4, 4)
GUICtrlSetFont(-1, 36, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

Global $Answer
$Answer[0] = "<< " & $Text & " will be for you what you want it to be.>>"
$Answer[1] = "<< " & $Text & ", in touch with tomorrow.>>"

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sloganize
                        SloganizeTxt()
    EndSwitch
WEnd

Func SloganizeTxt()
    $SloganizeNow = GuiCtrlRead($Text)
    $Random = Random($Answer)
    GUICtrlSetData($Random)
EndFunc

The image is attached below.

Thankyou for helping in advance,

Secure

Not sure what you are looking for but I some what fixed your script NO Errors

CODE
#include <GUIConstants.au3>

Dim $Answer[3]

$sGui = GUICreate("Sloganizer.Net :: Secure_ICT AutoIt Version", 554, 338, -1, -1)

GUISetBkColor(0xFFFFFF)

$Pic1 = GUICtrlCreatePic("logo.jpg", 0, 16, 553, 81, BitOR($SS_NOTIFY,$WS_GROUP))

$Text = GUICtrlCreateInput("Text", 72, 112, 385, 21)

$sloganize = GUICtrlCreateButton("Sloganize", 152, 144, 217, 25, 0)

$FinalText = GUICtrlCreateLabel("", 72, 192, 4, 4)

GUICtrlSetFont(-1, 36, 800, 0, "Arial")

GUICtrlSetColor(-1, 0xFF0000)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUISetState(@SW_SHOW)

Global $Answer

$Answer[1] = "<< " & $Text & " will be for you what you want it to be.>>"

$Answer[2] = "<< " & $Text & ", in touch with tomorrow.>>"

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $sloganize

EndSwitch

WEnd

Func SloganizeTxt()

$SloganizeNow = GuiCtrlRead($Text)

$Random = Random($Answer)

GUICtrlSetData($sGui ,$Random)

EndFunc

Added:

Dim $Answer[3]

Changed

$Answer[1] = "<< " & $Text & " will be for you what you want it to be.>>"

$Answer[2] = "<< " & $Text & ", in touch with tomorrow.>>"

Fixed

GUICtrlSetData($sGui ,$Random)

Edited by madmikep
Link to comment
Share on other sites

Mine version:

#include <GUIConstants.au3>

$sGui = GUICreate("Sloganizer.Net :: Secure_ICT AutoIt Version", 554, 400, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("logo.jpg", 0, 16, 553, 81, BitOR($SS_NOTIFY,$WS_GROUP))
$Text = GUICtrlCreateInput("Text", 72, 112, 385, 21)
$sloganize = GUICtrlCreateButton("Sloganize", 152, 144, 217, 25, 0)
$FinalText = GUICtrlCreateLabel("", 72, 192, 400, 200)
GUICtrlSetFont(-1, 36, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

Global $Answer[3]
$Answer[0] = "%1 will be for you what you want it to be."
$Answer[1] = "%1, in touch with tomorrow."
$Answer[2] = "Forever with %1 :-)"

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sloganize
            SloganizeTxt()
    EndSwitch
WEnd

Func SloganizeTxt()
    $SloganizeNow = GuiCtrlRead($Text)
    $Random = Random(0,UBound($Answer)-1,1)
    $result = $Answer[$Random]
    $result = StringReplace($result,'%1', $SloganizeNow)
    GUICtrlSetData($FinalText, "<< " & $result & " >>")
EndFunc

EDIT:

Slogans can be saved in TXT file (each slogan at one line) and read by _FileReadToArray()

Edited by Zedna
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...