Jump to content
Sign in to follow this  
James

Random and Global Variables

Recommended Posts

James

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

Share this post


Link to post
Share on other sites
flyingboz

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.

Share this post


Link to post
Share on other sites
madmikep

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

Share this post


Link to post
Share on other sites
Zedna

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

Share this post


Link to post
Share on other sites
James

Zedna you rule! Thanks mate! Its obvious now that I look but I don't understand the %1's? I get what that %1 means but thwy is that used and not a $?

I get it now, I missed the StringReplace! lol

Edited by Secure_ICT

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.