Jump to content
Sign in to follow this  
gianfun

Help with Arrays and checking which array was clicked

Recommended Posts

gianfun

Hi people!

So, i'm doing this little "map maker" for a little game im going to try and make (lol)

So, I've made labels, which will be the tile. The radio's will define what colour will be "chosen" to colour the label, then when a label is clicked, it would change colour. Heres the script:

#include<guiconstants.au3>
opt("guioneventmode",1)
opt("guicloseonesc",1)


global $map[10][10], $color
guicreate("Map Maker", 400,400)
GUISetOnEvent($gui_event_close, "bye")


for $x = 1 to 9
    for $y = 1 to 9
    $map[$x][$y] = GUICtrlCreateLabel("", 16*$x + 35,16*$y + 35,15,15)
    GUICtrlSetOnEvent(-1,"color")
    GUictrlSetStyle($map[$x][$y],$ss_center)
    GUICtrlSetBkColor(-1, "0x000000")
    next
next

GUICtrlCreateLabel("", 240, 43, 15,15)
    GUICtrlSetBkColor(-1, 0x00ff00)
$grasstool = GUICtrlCreateRadio("Grass",260,40)
GUICtrlSetOnEvent($grasstool,"settool")

GUICtrlCreateLabel("", 240, 63, 15,15)
    GUICtrlSetBkColor(-1, 0x804000)
$roadtool = GUICtrlCreateRadio("Road",260,60)
GUICtrlSetOnEvent($roadtool,"settool")

GUICtrlCreateLabel("", 240, 83, 15,15)
    GUICtrlSetBkColor(-1, 0xe2e2e5)
$Buildingtool = GUICtrlCreateRadio("Building",260,80)
GUICtrlSetOnEvent($Buildingtool,"settool")

GUICtrlCreateLabel("", 240, 103, 15,15)
    GUICtrlSetBkColor(-1, 0x00ffff)
$portaltool = GUICtrlCreateRadio("Portal",260,100)
GUICtrlSetOnEvent($portaltool,"settool")

guisetstate()

func settool()
    MsgBox(0,"hi",$color)
    if guictrlread($grasstool) = 1 then $color = 0x00ff00
    if guictrlread($roadtool) = 1 then $color = 0x804000
    if guictrlread($Buildingtool) = 1 then $color = 0xe2e2e5
    if guictrlread($portaltool) = 1 then $color = 0x00ffff
EndFunc
        
func color()
    GUICtrlSetBkColor($map,$color)
EndFunc


func bye()
    Exit
EndFunc

while 1
WEnd

I would like to know if there is a way for the func color to find out which label i clicked.

Thanks in advance!


My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Share this post


Link to post
Share on other sites
SadBunny

For really cool functions for all kinds of image manipulation, check out prospeed, as for instance described here:

http://www.autoitscript.com/forum/index.php?showtopic=71654

It both can greyscale and compare for you, or so it seems. The grayscaling works fine, I used it, the compare I have never used but it seems to work too, and fast.

Sorry, in some WEIRD way this posted this as reply to the wrong topic...

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
SadBunny

Anyway, a possibly more useful answer: if you create labels and assign the result of the creation to a variable, you can just check which one was clicked by GuiGetMsg().

Is this about what you need?

HotKeySet("{ESC}", "_quit")

$gui = GUICreate("test", 600, 400)

$l1 = GUICtrlCreateLabel("test1", 10, 10, 300, 50)
$l2 = GUICtrlCreateLabel("test2", 10, 100, 300, 50)

GUICtrlSetBkColor($l1, 0xFF0000)
GUICtrlSetBkColor($l2, 0x00FF00)

GUISetState()

While 1
 Sleep(10)
 $msg = GUIGetMsg()
 If $msg=$l1 Then MsgBox(0,0,"The red label was clicked")
 If $msg=$l2 Then MsgBox(0,0,"The green label was clicked")
WEnd

Func _quit()
 Exit
EndFunc  ;==>_quit

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
gianfun

nah, wont work.

Its on the "guioneventmode" option. Guigetmsg() doesnt go :)

and its arrays. I would like the function to see what array had been clicked... Is that even possible?


My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Share this post


Link to post
Share on other sites
SadBunny

Now I don't mean to nag, but how can you click an array? You want to click some graphical element, right? Possibly you could get the mouse position, and then determine what color is present on that pixel coordinate.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
rambo3889

@GUI_CtrlId.


My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! you’re the best in town Fight!

Share this post


Link to post
Share on other sites
SadBunny

@GUI_CtrlId.

Or that ofcourse! :) Just like always, I took 3 right turns instead of 1 left :)

:)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
gianfun

hum... I tried it several ways, but just couldn't make it work.

Clicking the labels isn't even calling the function...

So now my problem is why? arrays i guess...

#include<guiconstants.au3>
opt("guioneventmode",1)
opt("guicloseonesc",1)


global $map[10][10], $color = 0x00ffff
guicreate("Map Maker", 400,400)
GUISetOnEvent($gui_event_close, "bye")


for $x = 1 to 9
    for $y = 1 to 9
    $map[$x][$y] = GUICtrlCreateLabel("", 16*$x + 35,16*$y + 35,15,15)
    GUICtrlSetOnEvent($map[$x][$y],"color")
    GUictrlSetStyle($map[$x][$y],$ss_center)
    GUICtrlSetBkColor(-1, 0xff0000)
    next
next

GUICtrlCreateLabel("", 240, 43, 15,15)
    GUICtrlSetBkColor(-1, 0x00ff00)
$grasstool = GUICtrlCreateRadio("Grass",260,40)
GUICtrlSetOnEvent($grasstool,"settool")

GUICtrlCreateLabel("", 240, 63, 15,15)
    GUICtrlSetBkColor(-1, 0x804000)
$roadtool = GUICtrlCreateRadio("Road",260,60)
GUICtrlSetOnEvent($roadtool,"settool")

GUICtrlCreateLabel("", 240, 83, 15,15)
    GUICtrlSetBkColor(-1, 0xe2e2e5)
$Buildingtool = GUICtrlCreateRadio("Building",260,80)
GUICtrlSetOnEvent($Buildingtool,"settool")

GUICtrlCreateLabel("", 240, 103, 15,15)
    GUICtrlSetBkColor(-1, 0x00ffff)
$portaltool = GUICtrlCreateRadio("Portal",260,100)
GUICtrlSetOnEvent($portaltool,"settool")

GUICtrlSetBkColor($map[1][1], 0x00ffff)

guisetstate()

func settool()
    MsgBox(0,"hi",$color)
    if guictrlread($grasstool) = 1 then $color = 0x00ff00
    if guictrlread($roadtool) = 1 then $color = 0x804000
    if guictrlread($Buildingtool) = 1 then $color = 0xe2e2e5
    if guictrlread($portaltool) = 1 then $color = 0x00ffff
EndFunc
        
func color()
    MsgBox(0,"test","test2")
    GUICtrlSetBkColor(@GUI_CtrlId ,$color)
EndFunc


func bye()
    Exit
EndFunc

while 1
    sleep(10)
    $msg = GUIGetMsg()
    if $msg = $map[1][1] then MsgBox(0,"test,","test1")

WEnd

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Share this post


Link to post
Share on other sites
enaiman

Try this:

#include<GuiConstants.au3>
opt("guioneventmode",1)
opt("guicloseonesc",1)


global $map[10][10], $color = 0x00ffff
guicreate("Map Maker", 400,400)
GUISetOnEvent($gui_event_close, "bye")


for $x = 1 to 9
    for $y = 1 to 9
    $map[$x][$y] = GUICtrlCreateLabel("", 16*$x + 35,16*$y + 35,15,15)
    GUICtrlSetOnEvent($map[$x][$y],"color")
    ;GUictrlSetStyle($map[$x][$y],$ss_center)  - Useless, it creates all your problems
    GUICtrlSetBkColor(-1, 0xff0000)
    next
next

GUICtrlCreateLabel("", 240, 43, 15,15)
    GUICtrlSetBkColor(-1, 0x00ff00)
$grasstool = GUICtrlCreateRadio("Grass",260,40)
GUICtrlSetOnEvent($grasstool,"settool")

GUICtrlCreateLabel("", 240, 63, 15,15)
    GUICtrlSetBkColor(-1, 0x804000)
$roadtool = GUICtrlCreateRadio("Road",260,60)
GUICtrlSetOnEvent($roadtool,"settool")

GUICtrlCreateLabel("", 240, 83, 15,15)
    GUICtrlSetBkColor(-1, 0xe2e2e5)
$Buildingtool = GUICtrlCreateRadio("Building",260,80)
GUICtrlSetOnEvent($Buildingtool,"settool")

GUICtrlCreateLabel("", 240, 103, 15,15)
    GUICtrlSetBkColor(-1, 0x00ffff)
$portaltool = GUICtrlCreateRadio("Portal",260,100)
GUICtrlSetOnEvent($portaltool,"settool")

GUICtrlSetBkColor($map[1][1], 0x00ffff)

guisetstate()

func settool()
    MsgBox(0,"hi",$color)
    if guictrlread($grasstool) = 1 then $color = 0x00ff00
    if guictrlread($roadtool) = 1 then $color = 0x804000
    if guictrlread($Buildingtool) = 1 then $color = 0xe2e2e5
    if guictrlread($portaltool) = 1 then $color = 0x00ffff
EndFunc
        
func color()
    ;MsgBox(0,"test","test2")
    GUICtrlSetBkColor(@GUI_CtrlId ,$color)
EndFunc


func bye()
    Exit
EndFunc

while 1
    sleep(10)
    ;got rid of your other lines of script - bad idea to mix modes
WEnd

That Style thing messed your script.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
gianfun

Yay!!

thanks!!

it worked now!!

and yeah, i know it is a bad idea to mix modes, it had been one of the attempts to make it work which i forgot to take out XD


My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

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  

×