Jump to content

I need a little help concerning variables (I think)


Ekaj
 Share

Recommended Posts

I'm pretty new to AutoIt and coding in general, so appologies if I use any incorrect terminology or my code is awful.

So far I have:

CODE
hotkeyset ("{F8}", "startstop")

hotkeyset ("{F9}", "quit")

hotkeyset ("{F10}", "Pre")

Global $on = 0

Global $pre = 0

$var = IniRead("pokemon.ini", "Walk", "WalkTime", "Whoops")

While 1

If $on Then

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Left Down}")

Sleep($var)

ControlSend("VisualBoyAdvance", "", "", "{Left Up}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Right Down}")

Sleep($var)

ControlSend("VisualBoyAdvance", "", "", "{Right Up}")

EndIF

WEnd

While 1

If $pre Then

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

Endif

WEnd

Func Pre()

$pre = NOT $pre

EndFunc

Func startstop()

$on = NOT $on

EndFunc

Func quit()

Exit(0)

EndFunc

It all works flawlessly. However, I want to add an ElseIf statement to:

CODE
While 1

If $pre Then

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

Endif

WEnd

So that It would look something like this:

CODE
While 1

If $pre Then

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

ElseIf $pre = 0 Then

SoundSetWaveVolume(100)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space UP}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X UP}")

Endif

WEnd

The problem is, I don't know how to use the pre function to manipulate the $pre variable in such away that I can achieve what I want. Basically what I'd like to happen is:

The first time I press F10

CODE
SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

is executed, then next time I press it

CODE
SoundSetWaveVolume(100)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space UP}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X UP}")

is executed.

Basically, I need to know what needs to go here:

CODE

Func Pre()

HERE

EndFunc

In order to achieve what I'd like.

Thanks for any help.

Edited by Ekaj
Link to comment
Share on other sites

What editor do you use?

The SciTe eeditor that comes with AutoIt suports ConsoleWrite.

So if you run your program from within SciTe you could use code like this to figure out the state of your variables.

Func Pre()
    $pre = NOT $pre
    ConsoleWrite($pre & @CRLF)
EndFunc

Func startstop()
    $on = NOT $on
    ConsoleWrite($on & @CRLF)
EndFunc

It seems like you basically know what your doing so just keep at it..:)

Link to comment
Share on other sites

$pre = not $pre

I think that should do it

I think I'm struggling to put across what I'm actually trying to do, or possibly not understanding your responses because my AutoIt knowledge is so poor. Apologies if its the latter.

When I press F10 the first time I want this to happen:

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

When I press it the second time I want this to happen:

SoundSetWaveVolume(100)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space UP}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X UP}")

The code as it stands at the moment looks like this:

hotkeyset ("{F10}", "Pre")

If $love Then

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

ElseIf $love = NOT $love Then

SoundSetWaveVolume(100)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space UP}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X UP}")

Endif

and

Func Pre()

$love = NOT $love

EndFunc

The problem I have is that I don't know how I need to manipulate $love within the Pre function in order to achieve what I want.

I realize I could easily achieve what I want by assigning another function to another key, but I've spent so long trying to figure this out now, I'd just like to know how to do it.

[i've bolded the bits that are obviously wrong and/or I'm struggling with].

Again, responses are much appreciated.

Edit; Is there anything in Autoit which would look something like this:

If $love = Even Number

and

If $love = Odd Number?

Because if that is the case then I could just use

$love = $love + 1 within the pre() function.

Edited by Ekaj
Link to comment
Share on other sites

Second Edit: I only just noticed you posted this:

Func Pre()

If $love = 1 Then

$love = 0

Else

$love = 1

EndIf

EndFunc

So I combined it with:

If $love = 1 Then

SoundSetWaveVolume(0)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space Down}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X Down}")

ElseIf $love = 0 Then

SoundSetWaveVolume(100)

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{Space UP}")

Sleep(10)

ControlSend("VisualBoyAdvance", "", "", "{X UP}")

Endif

It looks like it should do what I want, but it doesn't seem to work. :/

Have I made a mistake somewhere?

Edited by Ekaj
Link to comment
Share on other sites

I got it to work. I realized that I could just put it all within the pre() function since the While statements were redundant anyway. Yay for learning something. I can see this AutoIt thing wont be as easy as I'd hoped.

Thanks for all the help.

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...