My excuse generator.

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

My excuse generator.

Post by Ant » Tue Mar 10, 2009 10:47 pm

Well this might seem asthough i have jumped right in.

But i would just like to know where to start.

I made an excuse generator in AutoIT a while back. And would LOVE to convert it into revolution.

Code: Select all

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIListbox.au3>


$Form1 = GUICreate("oExcuse Generator", 258, 275, 193, 125)
$Button1 = GUICtrlCreateButton("Generate", 8, 8, 241, 25, 0)
$List1 = GUICtrlCreateList("", 8, 40, 241, 201, BitOR($WS_VSCROLL,$WS_BORDER))
$Label1 = GUICtrlCreateLabel("Created By: oToom ( Ant )", 64, 248, 126, 17)
GUISetState(@SW_SHOW)

$Thing1 = _ArrayCreate(9, "My mom ", "My dad ", "My sister ", "My brother ", "My dog ", "My cat ", "My hamster ", "The Police ", "Hitler ")
$DidSomething = _ArrayCreate(8, "blew up ", "smashed ", "hit ", "puked on ", "punched ", "spat on ", "ate ", "threw ")
$Thing2 = _ArrayCreate(10, "my mom.", "my dad.", "my sister.", "my brother.", "my dog.", "my cat.", "my hamster.", "the police.", "hitler.", "my house.", "my homework.")

HotKeySet("^c", "_Copy")

While 1
    $nMsg = GUIGetMsg()    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            MsgBox(0, "oExcuse Generator", "Excuse generator created by oToom, ( Ant ).")
            Exit
            
        Case $Button1
            $Excuse = $Thing1[Random(1, 9, 1)] & $DidSomething[Random(1, 8, 1)] & $Thing2[Random(1, 10, 1)]
            _GUICtrlListBox_InsertString($List1, $Excuse, 0)

    EndSwitch
WEnd

Func _Copy()
    $Selected = _GUICtrlListBox_GetCurSel($List1)
    $SelectedText = GUICtrlRead($List1, $Selected)
    ClipPut($SelectedText)
EndFunc
That is the autoit code.

Any help?

Thanks guys and girls.

@Ant

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Tue Mar 10, 2009 11:37 pm

Hi Ant,

I have no idea what AutoIT is but try this in a button

Code: Select all

on mouseUp pMouseBtnNo
    put "My mom ,My dad , My sister , My brother , My dog , My hamster , The Police , Hitler " into thing1
    put "blew up ,smashed ,hit ,puked on ,spat on ,ate ,threw " into didSomething
    put "my mom.,my dad.,my sister.,my brother.,my dog.,my cat.,my hamster.,the police.,hitler.,my house.,my homework." into thing2
    repeat
        answer any item of thing1 & any item of didSomething & any item of thing2 with "Next" or "cancel"
        if it is "cancel" then 
            answer "oExcuse" & return & "Excuse generator created by oToom, ( Ant )."
            exit repeat
        end if
    end repeat
end mouseUp
regards
Bernd

Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

Post by Ant » Wed Mar 11, 2009 12:04 am

I think i get that.
The only part i am struggling on is..

Code: Select all

repeat
        answer any item of thing1 & any item of didSomething & any item of thing2 with "Next" or "cancel"
        if it is "cancel" then
            answer "oExcuse" & return & "Excuse generator created by oToom, ( Ant )."
            exit repeat
        end if
    end repeat 
That part.

May i ask you to explain or break it down to help me out?

Thanks bn.

@Ant

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Wed Mar 11, 2009 12:18 am

that part is an endless repeat loop. Unless of course you hit cancel, then it shows the credits (excuse generator, etc) and exits the repeat loop.

the actual random excuse generator is in
answer any item of thing1 & any item of didSomething & any item of thing2 with "Next" or "cancel"
it takes any (=random) item (an item is by default anything separated by ','
you can change it with the itemdelimiter.

'Answer' puts it into a dialog box.

If you make a stack with a button and a field, set the name of the field in the inspector to "myField" and put

Code: Select all

on mouseUp
    put "My mom ,My dad , My sister , My brother , My dog , My hamster , The Police , Hitler " into thing1
    put "blew up ,smashed ,hit ,puked on ,spat on ,ate ,threw " into didSomething
    put "my mom.,my dad.,my sister.,my brother.,my dog.,my cat.,my hamster.,the police.,hitler.,my house.,my homework." into thing2
    put any item of thing1 & any item of didSomething & any item of thing2 into field "myField"
end mouseUp
into the script of the button then you have the same functionality without the repeat stuff, you just hit the button and you get a new excuse

if you will excuse me now, My dog blew up my house. :)

I hope this explains it a bit.
regards
Bernd

Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

Post by Ant » Wed Mar 11, 2009 12:31 am

Yes, this helped me out, thanks.

Also i saw that you put, field.
How may i do this for a listbox or alike?

Thanks again Bernd.

@Ant

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Wed Mar 11, 2009 10:19 am

How may i do this for a listbox or alike?
what do you mean by listbox?
How do you want to display the excuses, please explain. There are many ways to display information in Rev, it all depends what you want to achieve.
regards
bernd

Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

Post by Ant » Sat Mar 14, 2009 10:18 am

Ah sorry, no worries. I thught field would have been like an.. texbox or something. But nah,

Thanks for the great help Bn. : )


Greatly appreciated!

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sat Mar 14, 2009 12:34 pm

A field is a container that can display much information in different ways, eg scrolling list field. The container is "field" but it can have different properties set. I think a "listbox" to you imay mean the same as a field where the "listBehaviour" property is set to true.
If you want to add multiple lines to a field (of whatever sort) then you can "put" a return character (which has a constant name declaration of "cr", "linefeed", or "lf" in Rev - and it will work out the appropriate line endings for different operating systems by itself) and the text you want to add "after" the field.

So you can

Code: Select all

put "This is line one" into field "FieldList"
put cr & "This is line two" after field "FieldList"
Make sure the second line puts the text after not into the field.

Or... do you mean that a listbox is like a Combo Box? In Rev, that would be a Button of style of menu with the menuMode of comboBox set.

HTH

Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

Post by Ant » Sat Mar 14, 2009 2:01 pm

Nope you are correct, as in listbox i meant as in so i could add several entries into the list.

So they would keep adding to the top, etc, so you could still see your previous excuses.

Thanks, SparkOut
[img]http://i44.tinypic.com/xkrj9y.png[/img]
[url=http://www.flowgraphix.net/kjar]Knowledge Jar[/url]

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sat Mar 14, 2009 2:30 pm

If you wanted to add to the top of the field, then you can

Code: Select all

put "new line here" & cr before field "fieldList"
btw.

Glad it helps.

Ant
Posts: 7
Joined: Mon Mar 09, 2009 8:57 pm

Post by Ant » Sat Mar 14, 2009 2:51 pm

Ahhh coool thanks.
Yes that was a great help,

Thankyou!
[img]http://i44.tinypic.com/xkrj9y.png[/img]
[url=http://www.flowgraphix.net/kjar]Knowledge Jar[/url]

Post Reply

Return to “Converting to LiveCode”