Jump to content

Recommended Posts

Posted

I have made buttons before, but never seen this error, what can cause it? 

If i hit Button $Cheat it works once but as soon $answer is used  $Cheat will be used as well. why it happens? if i dont press button $Cheat then everything i snormal, but if i press button  $Cheat it will be trigered each time i use $answer.

Its multiplication program for my child to leart to multiplay :D

func Main()
While 1

 $idMsg = GUIGetMsg()
   Select
      Case $idMsg = $answer
         Global $Answer1 = GUICtrlRead($answer)
         Vastus()
      Case $idMsg = $Cheat
         Consolewrite("ITS ACTIVE"&@crlf)
         Cheat()

EndSelect

      If $Score > 150 Then  $Grade = 5
      If $Score > 120 Then  $Grade = 4
      If $Score > 75 Then  $Grade = 3
      If $Score > 20 Then  $Grade = 2
      If $Score > -100 Then  $Grade = 1
      If $Tehteid = 0 Then Valmis()
WEnd
EndFunc

 

Posted

As you didn't post the full scipt it is hard to tell why it doesn't work.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
3 minutes ago, water said:

As you didn't post the full scipt it is hard to tell why it doesn't work.

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <StaticConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>




Global $Vastus = 0
Global $Score = 0
Global $Tehteid = 10
Global $Grade = 0
$HWnd = GUICreate("Korrutamine", 400, 300, -1, -1, $WS_POPUP+$WS_BORDER)
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState()
HotKeySet("{ESC}", "Stop")
GUICtrlCreateLabel("KORRUTAMINE Autor dersiniar@gmail.com", 25, 2, 350, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetFont(-1, 14)

Global $Info = GUICtrlCreateLabel("", 100, 180, 150, 70)
GUICtrlSetColor(-1, 0x983300)
GUICtrlSetFont(-1, 30)

Global $tehe = GUICtrlCreateLabel("10", 60, 120, 160, 60)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 30)


Global $answer = GUICtrlCreateInput("", 240, 120, 100, 45)
GUICtrlSetFont($answer, 24, $FW_NORMAL,  $GUI_FONTITALIC)
Global $punktid = GUICtrlCreateLabel("Punktid: "    & " Tehteid jäänud veel " & $Tehteid, 50, 30, 300, 20)
GUICtrlSetColor(-1, 0x48CE76)
GUICtrlSetFont(-1, 14)

         Global $Cheat = GUICtrlCreateButton("Spikker", 300, 260, 85, 35)
         GUICtrlSetColor( $Cheat, 0xDD4F43)
         GUICtrlSetFont($Cheat, 16)
Global $Info2 = GUICtrlCreateLabel("Spikkri kasutamine" & @CRLF & "võtab -10 punkti", 180, 260, 120, 80)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 10)
    Global $idMsg = 0
Start()
func Main()
While 1

 $idMsg = GUIGetMsg()
   Select
      Case $idMsg = $answer
         Global $Answer1 = GUICtrlRead($answer)
         Vastus()
      Case $idMsg = $Cheat
         Consolewrite("ITS ACTIVE"&@crlf)
         Cheat()

EndSelect

      If $Score > 150 Then  $Grade = 5
      If $Score > 120 Then  $Grade = 4
      If $Score > 75 Then  $Grade = 3
      If $Score > 20 Then  $Grade = 2
      If $Score > -100 Then  $Grade = 1
      If $Tehteid = 0 Then Valmis()
WEnd
EndFunc
Func Cheat()
GUICtrlSetData($info,  $Vastus)
$Score -= 10
GUICtrlSetData($punktid, "Punktid: " &$Score & " Tehteid jäänud veel " & $Tehteid)
Sleep ( 1000)
   EndFunc


Func Start()

   Global $Left = Random(0, 12, 1)
   Global $Right = Random(0, 12, 1)
   GUICtrlSetData($tehe, $Left & " X " & $Right & " = ")
   $Vastus = $Left*$Right
   GUICtrlSetData($answer, "")
Main()
   EndFunc

Func Valmis()
         GUICtrlSetData($info, "KÕIK VALMIS!" & @CRLF &  "Punkte kokku: " & $Score & @CRLF & "Hinne " & $Grade)
         GUICtrlSetColor( $info, 0x479F00)
         GUICtrlSetFont($info, 16)
         Global $Start = GUICtrlCreateButton("UUESTI", 150, 260, 85, 35)
         GUICtrlSetColor( $Start, 0xDD4F43)
         GUICtrlSetFont($Start, 16)

While 1
      Switch GUIGetMsg()
         Sleep( 100 )
      Case $Start
            Global $Vastus = 0
            Global $Score = 0
            Global $Tehteid = 160
            GUICtrlSetData($punktid, "Punktid: " &$Score & " Tehteid jäänud veel " & $Tehteid)
            GUICtrlDelete($Start)
            GUICtrlSetData($info, "")
            GUICtrlSetFont($info, 30)
            Start()
         EndSwitch
WEnd
   EndFunc
Func Vastus()


If $Vastus = $Answer1 Then
GUICtrlSetData($info, "Õige")
GUICtrlSetColor( $info, 0x479F00)
$Score += 1
$Tehteid -= 1
GUICtrlSetData($punktid, "Punktid: " &$Score & " Tehteid jäänud veel " & $Tehteid)
Sleep (1000)
GUICtrlSetData($info, "")
GUICtrlSetColor( $info, 0x2BA1C6)

Start()
Else
   GUICtrlSetData($answer, "")
   GUICtrlSetData($info, "Proovi Uuesti")
   GUICtrlSetColor($info, 0xDD4F43)
   $Score -= 1
   GUICtrlSetData($punktid, "Punktid: " &$Score & " Tehteid jäänud veel " & $Tehteid)
Sleep (1000)
GUICtrlSetData($info, "")
GUICtrlSetColor($info, 0x2BA1C6)
EndIf

   EndFunc
   Func Stop()
      Exit
   EndFunc
   Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
 EndFunc

I dont mind sharing it

Posted

@dersiniar 

does this work for you:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <StaticConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>




Global $Vastus = 0
Global $Score = 0
Global $Tehteid = 10
Global $Grade = 0
$hWnd = GUICreate("Korrutamine", 400, 300, -1, -1, $WS_POPUP + $WS_BORDER)
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState()
HotKeySet("{ESC}", "Stop")
GUICtrlCreateLabel("KORRUTAMINE Autor dersiniar@gmail.com", 25, 2, 350, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetFont(-1, 14)

Global $Info = GUICtrlCreateLabel("", 100, 180, 150, 70)
GUICtrlSetColor(-1, 0x983300)
GUICtrlSetFont(-1, 30)

Global $tehe = GUICtrlCreateLabel("10", 60, 120, 160, 60)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 30)


Global $answer = GUICtrlCreateInput("", 240, 120, 100, 45)
GUICtrlSetFont($answer, 24, $FW_NORMAL, $GUI_FONTITALIC)
Global $punktid = GUICtrlCreateLabel("Punktid: " & " Tehteid jäänud veel " & $Tehteid, 50, 30, 300, 20)
GUICtrlSetColor(-1, 0x48CE76)
GUICtrlSetFont(-1, 14)

Global $Cheat = GUICtrlCreateButton("Spikker", 300, 260, 85, 35)
GUICtrlSetColor($Cheat, 0xDD4F43)
GUICtrlSetFont($Cheat, 16)
Global $Info2 = GUICtrlCreateLabel("Spikkri kasutamine" & @CRLF & "võtab -10 punkti", 180, 260, 120, 80)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 10)
Global $idMsg = 0
Start()
func Main()
    While 1

        $idMsg = GUIGetMsg()
        Select
            Case $idMsg = $answer
                Global $Answer1 = GUICtrlRead($answer)
            Case $idMsg = $Cheat
                Vastus()
                Consolewrite("ITS ACTIVE" & @crlf)
                Cheat()

        EndSelect

        If $Score > 150 Then $Grade = 5
        If $Score > 120 Then $Grade = 4
        If $Score > 75 Then $Grade = 3
        If $Score > 20 Then $Grade = 2
        If $Score > -100 Then $Grade = 1
        If $Tehteid = 0 Then Valmis()
    WEnd
EndFunc   ;==>Main
Func Cheat()
    GUICtrlSetData($Info, $Vastus)
    $Score -= 10
    GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
    Sleep(1000)
EndFunc   ;==>Cheat


Func Start()

    Global $Left = Random(0, 12, 1)
    Global $Right = Random(0, 12, 1)
    GUICtrlSetData($tehe, $Left & " X " & $Right & " = ")
    $Vastus = $Left * $Right
    GUICtrlSetData($answer, "")
    Main()
EndFunc   ;==>Start

Func Valmis()
    GUICtrlSetData($Info, "KÕIK VALMIS!" & @CRLF & "Punkte kokku: " & $Score & @CRLF & "Hinne " & $Grade)
    GUICtrlSetColor($Info, 0x479F00)
    GUICtrlSetFont($Info, 16)
    Global $Start = GUICtrlCreateButton("UUESTI", 150, 260, 85, 35)
    GUICtrlSetColor($Start, 0xDD4F43)
    GUICtrlSetFont($Start, 16)

    While 1
        Switch GUIGetMsg()
            Case $Start
                Global $Vastus = 0
                Global $Score = 0
                Global $Tehteid = 160
                GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
                GUICtrlDelete($Start)
                GUICtrlSetData($Info, "")
                GUICtrlSetFont($Info, 30)
                Start()
        EndSwitch
        Sleep(100)
    WEnd
EndFunc   ;==>Valmis
Func Vastus()


    If $Vastus = $Answer1 Then
        GUICtrlSetData($Info, "Õige")
        GUICtrlSetColor($Info, 0x479F00)
        $Score += 1
        $Tehteid -= 1
        GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
        Sleep(1000)
        GUICtrlSetData($Info, "")
        GUICtrlSetColor($Info, 0x2BA1C6)

        Start()
    Else
        GUICtrlSetData($answer, "")
        GUICtrlSetData($Info, "Proovi Uuesti")
        GUICtrlSetColor($Info, 0xDD4F43)
        $Score -= 1
        GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
        Sleep(1000)
        GUICtrlSetData($Info, "")
        GUICtrlSetColor($Info, 0x2BA1C6)
    EndIf

EndFunc   ;==>Vastus
Func Stop()
    Exit
EndFunc   ;==>Stop
Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
EndFunc   ;==>WM_LBUTTONDOWN

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

  • Developers
Posted (edited)

There are several code issues in that code and I am sure you didn't run au3check as that comes up with an error.

issues:

  1. Never use sleeps in a GUI msg loop!
  2. Never call A func that was already called unless you really need to do nested calls. You are calling Start() at several places!

@ad777... did you actually test it before dumping you version of the code?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Jos

deriniar want fix for his problem that it,all i did is fix he's problem that it.:D

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

  • Developers
Posted (edited)
24 minutes ago, ad777 said:

deriniar want fix for his problem that it,all i did is fix he's problem that it.

You do not want to fix a car tire puncture of a car that is "total-loss" ;) 

So you are not doing any favors by changing the code when the code is flawed. Rather explain the code is flawed and let the OP learn!

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
On 4/3/2022 at 4:11 PM, ad777 said:

@dersiniar 

does this work for you:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <StaticConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>




Global $Vastus = 0
Global $Score = 0
Global $Tehteid = 10
Global $Grade = 0
$hWnd = GUICreate("Korrutamine", 400, 300, -1, -1, $WS_POPUP + $WS_BORDER)
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState()
HotKeySet("{ESC}", "Stop")
GUICtrlCreateLabel("KORRUTAMINE Autor dersiniar@gmail.com", 25, 2, 350, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetFont(-1, 14)

Global $Info = GUICtrlCreateLabel("", 100, 180, 150, 70)
GUICtrlSetColor(-1, 0x983300)
GUICtrlSetFont(-1, 30)

Global $tehe = GUICtrlCreateLabel("10", 60, 120, 160, 60)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 30)


Global $answer = GUICtrlCreateInput("", 240, 120, 100, 45)
GUICtrlSetFont($answer, 24, $FW_NORMAL, $GUI_FONTITALIC)
Global $punktid = GUICtrlCreateLabel("Punktid: " & " Tehteid jäänud veel " & $Tehteid, 50, 30, 300, 20)
GUICtrlSetColor(-1, 0x48CE76)
GUICtrlSetFont(-1, 14)

Global $Cheat = GUICtrlCreateButton("Spikker", 300, 260, 85, 35)
GUICtrlSetColor($Cheat, 0xDD4F43)
GUICtrlSetFont($Cheat, 16)
Global $Info2 = GUICtrlCreateLabel("Spikkri kasutamine" & @CRLF & "võtab -10 punkti", 180, 260, 120, 80)
GUICtrlSetColor(-1, 0x2BA1C6)
GUICtrlSetFont(-1, 10)
Global $idMsg = 0
Start()
func Main()
    While 1

        $idMsg = GUIGetMsg()
        Select
            Case $idMsg = $answer
                Global $Answer1 = GUICtrlRead($answer)
            Case $idMsg = $Cheat
                Vastus()
                Consolewrite("ITS ACTIVE" & @crlf)
                Cheat()

        EndSelect

        If $Score > 150 Then $Grade = 5
        If $Score > 120 Then $Grade = 4
        If $Score > 75 Then $Grade = 3
        If $Score > 20 Then $Grade = 2
        If $Score > -100 Then $Grade = 1
        If $Tehteid = 0 Then Valmis()
    WEnd
EndFunc   ;==>Main
Func Cheat()
    GUICtrlSetData($Info, $Vastus)
    $Score -= 10
    GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
    Sleep(1000)
EndFunc   ;==>Cheat


Func Start()

    Global $Left = Random(0, 12, 1)
    Global $Right = Random(0, 12, 1)
    GUICtrlSetData($tehe, $Left & " X " & $Right & " = ")
    $Vastus = $Left * $Right
    GUICtrlSetData($answer, "")
    Main()
EndFunc   ;==>Start

Func Valmis()
    GUICtrlSetData($Info, "KÕIK VALMIS!" & @CRLF & "Punkte kokku: " & $Score & @CRLF & "Hinne " & $Grade)
    GUICtrlSetColor($Info, 0x479F00)
    GUICtrlSetFont($Info, 16)
    Global $Start = GUICtrlCreateButton("UUESTI", 150, 260, 85, 35)
    GUICtrlSetColor($Start, 0xDD4F43)
    GUICtrlSetFont($Start, 16)

    While 1
        Switch GUIGetMsg()
            Case $Start
                Global $Vastus = 0
                Global $Score = 0
                Global $Tehteid = 160
                GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
                GUICtrlDelete($Start)
                GUICtrlSetData($Info, "")
                GUICtrlSetFont($Info, 30)
                Start()
        EndSwitch
        Sleep(100)
    WEnd
EndFunc   ;==>Valmis
Func Vastus()


    If $Vastus = $Answer1 Then
        GUICtrlSetData($Info, "Õige")
        GUICtrlSetColor($Info, 0x479F00)
        $Score += 1
        $Tehteid -= 1
        GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
        Sleep(1000)
        GUICtrlSetData($Info, "")
        GUICtrlSetColor($Info, 0x2BA1C6)

        Start()
    Else
        GUICtrlSetData($answer, "")
        GUICtrlSetData($Info, "Proovi Uuesti")
        GUICtrlSetColor($Info, 0xDD4F43)
        $Score -= 1
        GUICtrlSetData($punktid, "Punktid: " & $Score & " Tehteid jäänud veel " & $Tehteid)
        Sleep(1000)
        GUICtrlSetData($Info, "")
        GUICtrlSetColor($Info, 0x2BA1C6)
    EndIf

EndFunc   ;==>Vastus
Func Stop()
    Exit
EndFunc   ;==>Stop
Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
EndFunc   ;==>WM_LBUTTONDOWN

 

Lol no, its even more broken, But i fixed this with HotKeySet("{F5}", "Cheat") instead with button, this works

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
  • Recently Browsing   0 members

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