Jump to content

add a feature to a script


Recommended Posts

i have a script like a game of numerology

i want it instead of using an array with hardcoded elements (answers) to use a text file as a source for results. each line in the text file can be a result

how does it work? you type a string (a question) then i tchooses a random answer that you try to connect to the question. it`s like a game. it also has a log file that can log the questions and the answers

it must choose from a text file not from a hardcoded array of results. i will use it to test if it`s accurate. i`m half a psychic myself and i can always connect the answers to the questions with my logic, the answers can always be logical. the answers depend on the CPU, the CPU is like a robot brain. it was build based on CPU science. a human brain created the CPU for computers to generate solutions. we almost read a AI of the universe through programs that depend on CPU to create answers. the CPU can leak about god, the technology expert that created the universe as a technology concept, the universe can be a simulation in a computer. the CPU spills through numerology software. it`s going to lead us to answers directly from the entire simulation process.

it has to pick answers from atext file plz

 

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Date.au3>


Global $result1s[52]=["very sad tear", "very bad engagement", "three very bad words", "absolutely no love", "absolutely no realisation of a wish", "very bad situation in the family", "very bad health", "very bad work", "absolutely no money", "very bad way", "jack of spades", "queen of spades", "king of spades", "very happy tear", "very good engagement", "three very good words", "absolutely love", "absolutely realisation of a wish", "very good situation in the family", "very good health", "very good work", "absolutely money", "very good way", "jack of hearts", "queen of hearts", "king of hearts", "sad tear", "bad engagement", "three bad words", "no love", "no realisation of a wish", "bad situation in the family", "bad health", "bad work", "no money", "bad way", "jack of clubs", "queen of clubs", "king of clubs", "happy tear", "good engagement", "three good words", "love", "realisation of a wish", "good situation in the family", "good health", "good work", "money", "good way", "jack of diamonds", "queen of diamonds", "king of diamonds"]

_Main()

Func _Main()

    Local $button1
    Local $output, $die, $msg, $results1
    Local $file = FileOpen("ace.txt", 1)
    Local $g_idEdit

    GUICreate("ace play", 600, 200, -1, -1)
    $button1 = GUICtrlCreateButton("Result", 460, 110, 50, 30)

    $output1 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY))

    $g_idEdit = GUICtrlCreateEdit("", 60, 10, 450, 20, $SS_LEFT)

    $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN)
    GUICtrlSetFont($output, 8, 800, "", "Verdana")
    GUISetState()



    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $button1

                $results1 = Random(1, 51, 1)
                GUICtrlSetData($output1, $result1s[$results1])
                $read1 = GUICtrlRead($output1)


            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit))
            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1)



        EndSelect
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>_Main

 

Link to comment
Share on other sites

Maybe use  a .ini file ...

[answers]
101=very sad tear
102=very bad engagement
.....

.....

; Reads all key/value pairs from a section in a standard format .ini file.


IniReadSection ( "filename", "section" )

:) Take a look how i use .ini file in SideScrollRibon in the Function RibonLoad( )

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

6 hours ago, ioa747 said:

Maybe use  a .ini file ...

[answers]
101=very sad tear
102=very bad engagement
.....

.....

; Reads all key/value pairs from a section in a standard format .ini file.


IniReadSection ( "filename", "section" )

:) Take a look how i use .ini file in SideScrollRibon in the Function RibonLoad( )

 

can you add some more code to make it work?

Link to comment
Share on other sites

here is a script to read text out of a file

$maxlines=1
$filename="r:\File_0000.au3"

While 1
    $f=FileReadLine($filename,$maxlines)
    if @error=-1 then
        $maxlines=$maxlines-1
        ExitLoop
    EndIf

    $maxlines=$maxlines+1
WEnd

While 1
$i=InputBox("FileRead test","Please enter a line number to read" & @CRLF &"Enter "&($maxlines+1)& " to exit",1)
$txt=(FileReadLine($filename,$i)&@CRLF)
If @error=-1 then
    MsgBox(0,"The end","End of file is reached")
    Exit
EndIf
MsgBox (0,"Line "&$i,$txt)
WEnd

where does the 7720 come from ?
 

 

Some of my script sourcecode

Link to comment
Share on other sites

14 hours ago, Undisputed said:

it must choose from a text file not from a hardcoded array of results

So you need to read a txt file to an array to use in the script

#Include <Array.au3>

; here the txt file is built from the provided array
#cs
Global $result1s[52]=["very sad tear", "very bad engagement", "three very bad words", "absolutely no love", "absolutely no realisation of a wish", "very bad situation in the family", "very bad health", "very bad work", "absolutely no money", "very bad way", "jack of spades", "queen of spades", "king of spades", "very happy tear", "very good engagement", "three very good words", "absolutely love", "absolutely realisation of a wish", "very good situation in the family", "very good health", "very good work", "absolutely money", "very good way", "jack of hearts", "queen of hearts", "king of hearts", "sad tear", "bad engagement", "three bad words", "no love", "no realisation of a wish", "bad situation in the family", "bad health", "bad work", "no money", "bad way", "jack of clubs", "queen of clubs", "king of clubs", "happy tear", "good engagement", "three good words", "love", "realisation of a wish", "good situation in the family", "good health", "good work", "money", "good way", "jack of diamonds", "queen of diamonds", "king of diamonds"]

$str = _ArrayToString($result1s, @crlf)
FileWrite("results.txt", $str)
#ce

; read the file
$read = FileRead("results.txt")
; strip trailing white spaces if exist
$read = StringStripWS($read, 2)
; build an array to use in the script
$res = StringSplit($read, @crlf, 3)
_ArrayDisplay($res)

 

Link to comment
Share on other sites

5 hours ago, Undisputed said:

can you add some more code to make it work?

:) Take a look how i use .ini file in SideScrollRibon in the Function RibonLoad( )

as I said copy paste

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Date.au3>


;~ Global $result1s[52]=["very sad tear", "very bad engagement", "three very bad words", "absolutely no love", "absolutely no realisation of a wish", "very bad situation in the family", "very bad health", "very bad work", "absolutely no money", "very bad way", "jack of spades", "queen of spades", "king of spades", "very happy tear", "very good engagement", "three very good words", "absolutely love", "absolutely realisation of a wish", "very good situation in the family", "very good health", "very good work", "absolutely money", "very good way", "jack of hearts", "queen of hearts", "king of hearts", "sad tear", "bad engagement", "three bad words", "no love", "no realisation of a wish", "bad situation in the family", "bad health", "bad work", "no money", "bad way", "jack of clubs", "queen of clubs", "king of clubs", "happy tear", "good engagement", "three good words", "love", "realisation of a wish", "good situation in the family", "good health", "good work", "money", "good way", "jack of diamonds", "queen of diamonds", "king of diamonds"]

Global $result1s = RibonLoad()

_Main()

Func _Main()

    Local $button1
    Local $output, $die, $msg, $results1
    Local $file = FileOpen("ace.txt", 1)
    Local $g_idEdit

    GUICreate("ace play", 600, 200, -1, -1)
    $button1 = GUICtrlCreateButton("Result", 460, 110, 50, 30)

    $output1 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY))

    $g_idEdit = GUICtrlCreateEdit("", 60, 10, 450, 20, $SS_LEFT)

    $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN)
    GUICtrlSetFont($output, 8, 800, "", "Verdana")
    GUISetState()



    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $button1

                $results1 = Random(1, 51, 1)
                GUICtrlSetData($output1, $result1s[$results1])
                $read1 = GUICtrlRead($output1)


            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit))
            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1)



        EndSelect
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>_Main
;------------------------------------------------------------------------------
Func RibonLoad($RS_Name = "answers")    ; Ini Read
    ;ConsoleWrite("-->" & " " & $TM_Name & @CRLF)
    Local $MyIni = @ScriptDir & "\Ribon.ini"
    Local $iniFileExists = FileExists($MyIni)
    Local $index = 0
    Local $TMenuArray[1] = [$index]

    ; Checks if Ribon.ini not exists then make one.
    If Not $iniFileExists Then
        RibonMakeIni($MyIni)
    EndIf

    ; Read the INI section labelled '$RS_Name'. This will return a 2 dimensional array.
    Local $aArray = IniReadSection($MyIni, $RS_Name)

    ; Check if an error occurred.
    If Not @error Then
        ; Enumerate through the array displaying the keys and their respective values.
        For $i = 1 To $aArray[0][0]
            ReDim $TMenuArray[UBound($TMenuArray) + 1]
            $index += 1
            $TMenuArray[0] = $index     ; cnt
            $TMenuArray[$index] = $aArray[$i][1]
        Next
    EndIf

    ;_ArrayDisplay($TMenuArray, "$TMenu")
    Return $TMenuArray

EndFunc   ;==>RibonLoad
;------------------------------------------------------------------------------
Func RibonMakeIni($sFilePath)    ; Make new Ini file

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the Ribon.ini file.")
        Exit
    EndIf

    ; Write data to the file using the handle returned by FileOpen.
    FileWrite($hFileOpen, "[answers]" & @CRLF)
    FileWrite($hFileOpen, "101=very sad tear" & @CRLF)
    FileWrite($hFileOpen, "102=very bad engagement" & @CRLF)
    FileWrite($hFileOpen, "103=three very bad words" & @CRLF)

    For $i = 104 To 152
        FileWrite($hFileOpen, $i & "=..." & $i & @CRLF)
    Next

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    Sleep(300)

EndFunc   ;==>RibonMakeIni

 

I know that I know nothing

Link to comment
Share on other sites

2 hours ago, ioa747 said:

:) Take a look how i use .ini file in SideScrollRibon in the Function RibonLoad( )

as I said copy paste

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Date.au3>


;~ Global $result1s[52]=["very sad tear", "very bad engagement", "three very bad words", "absolutely no love", "absolutely no realisation of a wish", "very bad situation in the family", "very bad health", "very bad work", "absolutely no money", "very bad way", "jack of spades", "queen of spades", "king of spades", "very happy tear", "very good engagement", "three very good words", "absolutely love", "absolutely realisation of a wish", "very good situation in the family", "very good health", "very good work", "absolutely money", "very good way", "jack of hearts", "queen of hearts", "king of hearts", "sad tear", "bad engagement", "three bad words", "no love", "no realisation of a wish", "bad situation in the family", "bad health", "bad work", "no money", "bad way", "jack of clubs", "queen of clubs", "king of clubs", "happy tear", "good engagement", "three good words", "love", "realisation of a wish", "good situation in the family", "good health", "good work", "money", "good way", "jack of diamonds", "queen of diamonds", "king of diamonds"]

Global $result1s = RibonLoad()

_Main()

Func _Main()

    Local $button1
    Local $output, $die, $msg, $results1
    Local $file = FileOpen("ace.txt", 1)
    Local $g_idEdit

    GUICreate("ace play", 600, 200, -1, -1)
    $button1 = GUICtrlCreateButton("Result", 460, 110, 50, 30)

    $output1 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY))

    $g_idEdit = GUICtrlCreateEdit("", 60, 10, 450, 20, $SS_LEFT)

    $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN)
    GUICtrlSetFont($output, 8, 800, "", "Verdana")
    GUISetState()



    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $button1

                $results1 = Random(1, 51, 1)
                GUICtrlSetData($output1, $result1s[$results1])
                $read1 = GUICtrlRead($output1)


            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit))
            FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1)



        EndSelect
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>_Main
;------------------------------------------------------------------------------
Func RibonLoad($RS_Name = "answers")    ; Ini Read
    ;ConsoleWrite("-->" & " " & $TM_Name & @CRLF)
    Local $MyIni = @ScriptDir & "\Ribon.ini"
    Local $iniFileExists = FileExists($MyIni)
    Local $index = 0
    Local $TMenuArray[1] = [$index]

    ; Checks if Ribon.ini not exists then make one.
    If Not $iniFileExists Then
        RibonMakeIni($MyIni)
    EndIf

    ; Read the INI section labelled '$RS_Name'. This will return a 2 dimensional array.
    Local $aArray = IniReadSection($MyIni, $RS_Name)

    ; Check if an error occurred.
    If Not @error Then
        ; Enumerate through the array displaying the keys and their respective values.
        For $i = 1 To $aArray[0][0]
            ReDim $TMenuArray[UBound($TMenuArray) + 1]
            $index += 1
            $TMenuArray[0] = $index     ; cnt
            $TMenuArray[$index] = $aArray[$i][1]
        Next
    EndIf

    ;_ArrayDisplay($TMenuArray, "$TMenu")
    Return $TMenuArray

EndFunc   ;==>RibonLoad
;------------------------------------------------------------------------------
Func RibonMakeIni($sFilePath)    ; Make new Ini file

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the Ribon.ini file.")
        Exit
    EndIf

    ; Write data to the file using the handle returned by FileOpen.
    FileWrite($hFileOpen, "[answers]" & @CRLF)
    FileWrite($hFileOpen, "101=very sad tear" & @CRLF)
    FileWrite($hFileOpen, "102=very bad engagement" & @CRLF)
    FileWrite($hFileOpen, "103=three very bad words" & @CRLF)

    For $i = 104 To 152
        FileWrite($hFileOpen, $i & "=..." & $i & @CRLF)
    Next

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    Sleep(300)

EndFunc   ;==>RibonMakeIni

 

thanks it works

 

it doesnt write the answers to ace.txt though

Edited by Undisputed
Link to comment
Share on other sites

6 hours ago, Undisputed said:

thanks it works

 

it doesnt write the answers to ace.txt though

 why not ??

to me writes it in form

15/12/2022 6:24:33 hallo
15/12/2022 6:24:33 ...128

as result from line 45, 46           

FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit))

FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1)

Edited by ioa747

I know that I know nothing

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