Jump to content
Sign in to follow this  
MuffettsMan

How do you build a switch statement off an ini array >.<

Recommended Posts

MuffettsMan

I'm trying to build a switch statement based on any key / value pair in an array built from an ini file (this way i can update the gui which will write key/value pairs to the ini instead of me having to edit the switch statement every time i need to add or remove elements >.<

logic something like....

Switch <ini section one>

Case _IsPressed(<ini key>, $dll) ; 1 Key

While _IsPressed(<ini key>, $dll)

Sleep(10)

WEnd

TCPSend($ConnectedSocket,<ini value>)

EndSwitch

Switch <ini section two>

Case _IsPressed(<ini key>, $dll) ; 1 Key

While _IsPressed(<ini key>, $dll)

Sleep(10)

WEnd

TCPSend($ConnectedSocket,<ini value>)

EndSwitch

i know i can loop through every element of the array with something like....

For $i = 1 To $var[0][0]

MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])

Next

but that wouldn't make a dynamic switch statement.... how do you say switch on any key $var[$i][0] to $var[0][0] and get its corresponding value? >.< almost feels like i need a wildcard or is this even possible?


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites
MuffettsMan

if that doesn't make any sense :) basicly i have written a script that broadcasts selected keypresses to remote clients (for a game) and depending on what setup i'm running would depend on what keys i want sent... at the moment i'm just editing the switch statements manually but i know there has to be a better way... idealy i'd like to be able to load different ini files from the gui which would update the switch statements on the fly... i just don't know the syntax to have it read all the elements in the array or if its even possible...

this almost seems to work...

#include<misc.au3>

; 00000070 = F1

; 00000071 = F2

; 00000072 = F3

; 00000073 = F4

; 00000074 = F5

$dll = DllOpen("user32.dll")

$var = IniReadSection("C:\Temp\myfile.ini", "nomod")

If @error Then

MsgBox(4096, "", "Error occurred, probably no INI file.")

Else

For $i = 1 To $var[0][0]

; MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])

If _IsPressed($var[$i][0],$dll) Then

While _IsPressed($var[$i][0],$dll)

; do nothing

WEnd

ConsoleWrite( $var[$i][0] & " = " & $var[$i][1] & @CRLF)

EndIf

Next

EndIf

ini file looking like...

[nomod]

70=F1

71=F2

72=F3

73=F4

74=F5

EDIT: ignore this >.< added a continual loop and its reading the full ini array exactly as hoped!

Edited by zhenyalix

Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
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
Sign in to follow this  

×