HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: how come me.checked returns false if checked?  (Read 2993 times)

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
how come me.checked returns false if checked?
« on: Aug 26, 14, 03:17:29 PM »

method HE_onMouseClick(args references Class GUIMouseEvent)
 
  println(me.checked)

.

The above code in a checkbox derived object will return false if i check the checkbox, and true if i uncheck the checkbox.

Isn't that wierd?
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: how come me.checked returns false if checked?
« Reply #1 on: Aug 26, 14, 03:26:30 PM »

I have noticed that as well.  The method must be getting called before the value is actually changed.  Just means you need to use the opposite value.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #2 on: Aug 26, 14, 03:35:26 PM »

I can't, i run into problems when looping multiple checkboxes trying to determine which one is checked...its giving me all sorts of headaches...

There should be either a method which shows the true state of the checkbox or please fix , it's a BUG.
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #3 on: Aug 26, 14, 03:49:57 PM »

or....

for example, with this BUG, this piece of code would never resolve to a correct value:


heres some pseudo code:

---------------------------------
on click()

println (me.checked)

//listOfCheckBoxes contains all checkboxes including this one
loop i from 1 to listOfCheckBoxes.length
  //do some logic if the checkbox is checked
.
---------------------------------



i mean, i could probably find some workaround, but it calls for some dirty/ugly code
« Last Edit: Aug 26, 14, 03:53:30 PM by AWW_boss »
Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #4 on: Aug 26, 14, 03:53:05 PM »

This looks like it's working as expected to me, but I might not be understanding. A checkbox is currently Unchecked. You click on that checkbox which calls a method on click. Inside of that method, the checkbox is still Unchecked, as you'd want to do logic on the state of the checkbox when it's clicked, not the state it will become. This allows you to do logic on the upcoming change right? Or am I misunderstanding?
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #5 on: Aug 26, 14, 04:01:27 PM »

you understand correctly. but i claim that the correct implementation would be

A checkbox is currently Unchecked. You click on that checkbox which calls a method on click. Inside of that method, the checkbox is checked


The alternative would be (and this is only a sketch) to have 2 methods or something
1. on pre click --> inside this method it would be unchecked
2. on post click --> inside this method it would be checked
Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #6 on: Aug 26, 14, 04:15:25 PM »

That starts taking you into the age old mismatches between onMouseDown, onMouseUp and onClick. Pretty much in every language I've come across: flash, objective-c, etc, where there's an IDE with some prepacked UI elements for drag and drop use, the built in UI elements always use one of the ways, but invariably you want it to test using more than one. In my experience if you need the more complicated functionality you always end up having to do your own elements or logic from scratch.
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how come me.checked returns false if checked?
« Reply #7 on: Aug 26, 14, 05:01:25 PM »

all right, thanks for the feedback :)
Logged