Jump to content

'Scripting.Dictionary' error on decrease .Item(s)


Recommended Posts

Hi Forum!

I have found a bug or write something wrong...

The scripts idea is simple:

1. work with 'Scripting.Dictionary'

2. add many 'TYPE', with any name and any round number

3. you add a existent type in pilones

For my surprise, does not work!

The button [change], choose the pilone.

The button [fire], discharge the pilone's round.

I expect when choose pilone 0, descrease pilone's round 0 and choose pilone 1, decrease round's pilone 1.
 

The funciton dump show button fire decrease rounds from pilone 0 and 1!

Must be decrease 0 OR 1, not both.

The first type is decrease too!

What is wrong?

This is the script...

Best Regards, Detefon.

#include-once
#include <String.au3>
#include <Array.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>

Opt('GUIOnEventMode', 1)
Opt('GUIEventOptions', 1)
Opt('ExpandVarStrings', 1)
Opt('MustDeclareVars', 1)
Opt('WinWaitDelay', 25)

Global $oo = ObjCreate('Scripting.Dictionary')
$oo.CompareMode = 0
$oo.Add('pilones', ObjCreate('Scripting.Dictionary'))
$oo.Add('type', ObjCreate('Scripting.Dictionary'))
$oo.Add('default', 0)

AddType('blue', 21)
AddType('red', 22)
AddType('yellow', 23)
AddType('white', 24)

Func AddType($sName, $iRound)
    Local $oTemp = ObjCreate('Scripting.Dictionary')
    $oTemp.Add('name', $sName)
    $oTemp.Add('round', $iRound)
    $oo.Item('type').Add($oo.Item('type').Count, $oTemp)
EndFunc   ;==>AddType

Add(0, 0)
Add(1, 0)

Func Add($iPilone, $iType)
    $oo.Item('pilones').Add($iPilone, $oo.Item('type').Item($iType))
EndFunc   ;==>Add







dump($oo)

Func dump($oo, $key = '', $ident = 0)
    If IsDictionary($oo) Then
        Local $sKeys = $oo.Keys
        For $each In $sKeys
            If IsDictionary($oo.Item($each)) Or IsArray($oo.Item($each)) Then
                dump($oo.Item($each), ($key == '' ? '' : $key & '.') & $each, 0)
            Else
                ConsoleWrite(($ident == 0 ? '' : (_StringRepeat(' ', $ident))) & ($key == '' ? '' : $key & '.') & $each & ' = ' & $oo.Item($each) & @LF)
            EndIf
        Next
    Else
        If IsArray($oo) Then
            Switch UBound($oo, 0)
                Case 1
                    For $ii = 0 To UBound($oo, 1) - 1
                        If IsDictionary($oo[$ii]) Or IsArray($oo[$ii]) Then
                            dump($oo[$ii], $key & '[' & $ii & ']', 0)
                        Else
                            ConsoleWrite(($ident == 0 ? '' : (_StringRepeat(' ', $ident))) & ($key == '' ? '' : $key & '[') & $ii & '] = ' & $oo[$ii] & @LF)
                        EndIf
                    Next
                Case 2
                    For $ii = 0 To UBound($oo, 1) - 1
                        For $jj = 0 To UBound($oo, 2) - 1
                            If IsDictionary($oo[$ii][$jj]) Or IsArray($oo[$ii][$jj]) Then
                                dump($oo[$ii][$jj], $key & '[' & $ii & '][' & $jj & ']', 0)
                            Else
                                ConsoleWrite(($ident == 0 ? '' : (_StringRepeat(' ', $ident))) & ($key == '' ? '' : $key & '[') & $ii & '][' & $jj & '] = ' & $oo[$ii][$jj] & @LF)
                            EndIf
                        Next
                    Next
            EndSwitch
        Else

        EndIf
    EndIf
EndFunc   ;==>dump

Func IsDictionary($oo = Null)
    If Not (ObjName($oo, 2) == 'Scripting.Dictionary') Then Return 0
    Return 1
EndFunc   ;==>IsDictionary



Global $hGui[1], $aGuiSize[2] = [800, 600], $sGuiTitle = 'Título'
Global $hButtonChange, $hButtonFire

$hGui[0] = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1], -1, -1, Default, Default)
GUISetOnEvent($GUI_EVENT_CLOSE, '_quit')

$hButtonChange = GUICtrlCreateButton('change ' & $oo.Item('default'), 10, 10, 80, 20)
GUICtrlSetOnEvent($hButtonChange, '_button')

$hButtonFire = GUICtrlCreateButton('FIRE', 10, 40, 80, 20)
GUICtrlSetOnEvent($hButtonFire, '_buttonFire')

GUISetState(@SW_SHOWNORMAL)

While Sleep(10)

WEnd

Func _button()
    $oo.Item('default') += 1
    If $oo.Item('default') > ($oo.Item('pilones').Count - 1) Then $oo.Item('default') = 0
    GUICtrlSetData($hButtonChange, 'change ' & $oo.Item('default'))
EndFunc   ;==>_button

Func _buttonFire()
    ConsoleWrite( $oo.Item('default') & @LF)
    $oo.Item('pilones').Item( $oo.Item('default') ).Item('round') -= 1
    dump($oo)

EndFunc   ;==>_buttonFire

Func _quit()
    _exit()
EndFunc   ;==>_quit

Func _exit($input = 0)
    If $input Then ConsoleWrite('exit[' & $input & ']' & @LF)
    GUIDelete($hGui[0])
    Exit
EndFunc   ;==>_exit

In time...

I can make the result I want with Arrays, this is example:

Obs: for me, work with scripting.dicionary is more easy than arrays...
But, is not the main question, I want know why I can't produce the same result with scripting.dictionary, I am very curious.

#include-once
#include <String.au3>
#include <Array.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
 
Opt('GUIOnEventMode', 1)
Opt('GUIEventOptions', 1)
Opt('MustDeclareVars', 1)
Global $aTemp[1]
Global $aArm[4] = [0, $aTemp, $aTemp, $aTemp]
 
AddType('red', 21)
AddType('blue', 22)
AddType('yellow', 23)
AddType('white', 24)
 
Func AddType($sName, $iRound)
_ArrayAdd($aArm[2], $iRound)
_ArrayAdd($aArm[3], $sName)
EndFunc   ;==>AddType
 
Add(0)
Add(0)
 
Func Add($iType)
_ArrayAdd($aArm[1], ($aArm[2])[$iType + 1])
EndFunc   ;==>Add
 
Global $hGui[1], $aGuiSize[2] = [300, 200], $sGuiTitle = 'Título'
Global $hButtonChange, $hButtonFire
 
$hGui[0] = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1], -1, -1, Default, Default)
GUISetOnEvent($GUI_EVENT_CLOSE, '_quit')
 
$hButtonChange = GUICtrlCreateButton('change ' & $aArm[0], 10, 10, 80, 20)
GUICtrlSetOnEvent($hButtonChange, '_button')
 
$hButtonFire = GUICtrlCreateButton('FIRE', 10, 40, 80, 20)
GUICtrlSetOnEvent($hButtonFire, '_buttonFire')
 
GUISetState(@SW_SHOWNORMAL)
 
While Sleep(10)
WEnd
 
Func _button()
$aArm[0] += 1
If $aArm[0] > (UBound($aArm[1], 1) - 2) Then $aArm[0] = 0
GUICtrlSetData($hButtonChange, 'change ' & $aArm[0])
EndFunc   ;==>_button
 
Func _buttonFire()
Local $aa = $aArm[1]
$aa[$aArm[0] + 1] -= 1
If $aa[$aArm[0] + 1] < 0 Then $aa[$aArm[0] + 1] = 0
ConsoleWrite('weapon #' & $aArm[0] & ' name[ ' & ($aArm[3])[$aArm[0] + 1] & ' ] round[ ' & $aa[$aArm[0] + 1] & ' ]' & @LF)
$aArm[1] = $aa
EndFunc   ;==>_buttonFire
 
Func _quit()
_exit()
EndFunc   ;==>_quit
 
Func _exit($input = 0)
If $input Then ConsoleWrite('exit[' & $input & ']' & @LF)
GUIDelete($hGui[0])
Exit
EndFunc   ;==>_exit
 
Edited by Detefon

Visit my repository

Link to comment
Share on other sites

  • Moderators

Detefon,

That script looks a lot like game automation - would you care to explain why I am mistaken in so thinking? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba, is not a game automation... Believe me...
I am very serious about this...

I do not have (age and patience) for playing games (I am 41).

Lately I am very glad, I am work in full time with AutoIt in my work.

I am develop a application client-server to transfer client's information to server in PHP, using JSON.

Information like hardware, software.

In my free time, I write little codes to study GDIPlus.
I make many works with AutoIt in my work...
I build this panel for a local raffle.

 

Another work, using AutoIt and GDIPLus, is fotocam

I build a script to take a shot with webcam, resize and repositioning a new picture, put a children's name and print! In a month, was printed/make 10.000 children driver card's.

Each shot-print-write children name during 30 seconds! The interface is very simple, but functional.

post-53968-0-11417000-1406739451_thumb.p

In my free work, I always search something with use GDPlus, Json and Scripting.Dictionary.

The result with Json and Scripting.Dictionary is FRED. I use this in my work.

And... Finaly, in my free time I study with GDI + Scripting.Dicionary, and write a script to load a json map build with TileMapeEditor, this is result:

post-53968-0-98391600-1406739875_thumb.p

I know... work with graphics sometimes can be like or confunded with game automation by other peoples... but is not.

Its work. Its recreation for me.

I am very glad to read many woderful thinks in this forum, about many many things.

I am not automate nothing about game, I build my works, my algorithms to work.
 

Melba, you are very valued for me, I am very clear and sincery with you and glad to write about my doubts and work.

I so sorry to write everything in bad english.

Please, If you want know more, I very happy to write.

BR, Detefon.

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

  • Moderators

Detefon,

 

I am not automate nothing about game, I build my works, my algorithms to work

I am convinced - please carry on! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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