WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dual Button Assignment Issues
Goto page 1, 2  Next
 
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie
View previous topic :: View next topic  
Author Message
supershadowdude



Joined: 21 Mar 2007
Posts: 3

Digg It
PostPosted: Wed Mar 21, 2007 6:37 pm    Post subject: Dual Button Assignment Issues

Heya. I've been working on a code for the last few hours. I'm new, obviously, and I can't seem to wrap my head around this.

What I'm aiming for is pretty simple: If home is pressed down on the Wiimote, then nunchuk.Cbutton will function as the delete key and nunchuk.ZButton will function as the Insert key. If home is not pressed, however, I want Cbutton to work as key eight and Zbutton to work as key f12. Basically, it's very erratic in practice and I was wondering if someone could point out what I was doing wrong.

Quote:
//Targeting, Flight, and Flight Camera
if wiimote.home and wiimote.nunchuk.zbutton then
key.f12 = false
key.insert = true
endif
if Wiimote.home and not Wiimote.nunchuk.zbutton then
key.f12 = false
key.insert = false
endif
if wiimote.nunchuk.zbutton and not wiimote.home then
key.f12 = true
key.insert = false
endif
if wiimote.home and wiimote.nunchuk.cbutton then
key.delete = true
key.eight = false
endif
if wiimote.home and not wiimote.nunchuk.cbutton then
key.delete = false
key.eight = false
endif
if wiimote.nunchuk.cbutton and not wiimote.home then
key.delete = false
key.eight = true
endif
Back to top
View user's profile Send private message
TylerK



Joined: 18 Dec 2006
Posts: 384
Location: Springfield, IL

Digg It
PostPosted: Wed Mar 21, 2007 8:01 pm    Post subject: Re: Dual Button Assignment Issues

Looks like with that code you have to make sure you hold home, then press C or Z, then release C or Z, and then release home. If you release home early, it could cause problems with buttons being stuck.

Try this:
Code:
if (Wiimote.Home) then
  Delete = Wiimote.Nunchuk.CButton
  Insert = Wiimote.Nunchuk.ZButton
else
  Eight = Wiimote.Nunchuk.CButton
  F12 = Wiimote.Nunchuk.ZButton
endif


The above code might suffer from the same problem though. If so, try this instead:
Code:

if (Wiimote.Home) then
  Delete = Wiimote.Nunchuk.CButton
  Insert = Wiimote.Nunchuk.ZButton
  Eight = False
  F12 = False
else
  Eight = Wiimote.Nunchuk.CButton
  F12 = Wiimote.Nunchuk.ZButton
  Delete = False
  Insert = False
endif
Back to top
View user's profile Send private message
R.Legault



Joined: 24 Feb 2007
Posts: 111

Digg It
PostPosted: Wed Mar 21, 2007 8:48 pm    Post subject:

I am pretty sure it's best not to use assignments inside conditional statements.

Assignments are especially painful if you are trying to create a script switch script. If you want complete flexibility do not use any key assignments, use nested ifs for everything.

Code:
if Wiimote.Home
//I prefer using this method
   if Wiimote.Nunchuk.CButton
      press(Delete)
      wait 50ms
      release(Delete)
   endif
   if Wiimote.Nunchuk.ZButton
      press(Insert)
      wait 50ms
      release(Insert)
   endif

else //Wiimote.Home = false

//Some others prefer using this method
   if Wiimote.Nunchuk.CButton
      Eight = true
   else
      Eight = false
   endif

   if Wiimote.Nunchuk.ZButton
      F12 = true
   else
      F12 = false
   endif
endif
Back to top
View user's profile Send private message
supershadowdude



Joined: 21 Mar 2007
Posts: 3

Digg It
PostPosted: Wed Mar 21, 2007 9:38 pm    Post subject:

Thanks for the replies! Your help allowed me to get it working exactly like I wanted.
Back to top
View user's profile Send private message
TylerK



Joined: 18 Dec 2006
Posts: 384
Location: Springfield, IL

Digg It
PostPosted: Wed Mar 21, 2007 11:55 pm    Post subject:

R.Legault wrote:
I am pretty sure it's best not to use assignments inside conditional statements.

Assignments are especially painful if you are trying to create a script switch script. If you want complete flexibility do not use any key assignments, use nested ifs for everything.

Eh, kinda depends on what you're trying to do. Of the two methods you posted, I'd recommend using the second one. The first one (which you prefer) doesn't simulate holding down a button. It's constantly pressing then releasing it, which could lead to problems. For example, say you have one button that fires a gun in a game. If you tap the button it fires a small shot, but if you hold the button for a bit before releasing it, it charges up a big blast. If you used your first method, you'd not only be forced to use the small shots since you can't simulate the button being held down, you'd also have rapid fire with the small shots.

It would be great if there were some function in GlovePIE that could reset all the keys to false with one statement. I would love the hell out of that.
Back to top
View user's profile Send private message
SwedishFrog
Site Admin


Joined: 25 Jan 2007
Posts: 273
Location: New York

Digg It
PostPosted: Thu Mar 22, 2007 2:23 am    Post subject:

I've experienced what you guys are talking about. Sometimes if assignments are inside if statements, the keys never get released.

Anyway long story short, for problems like this I completely avoid if statements alltogether and just use logic functions. It works pretty good.

Here is my solution to the problem

key.delete = wiimote.nunchuk.Cbutton and wiimote.home
key.insert = wiimote.nunchuk.Zbutton and wiimote.home
key.eight = wiimote.nunchuk.cbutton and (not wiimote.home)
key.f12 = wiimote.nunchuk.zbutton and (not wiimote.home)


I use parenthesis in the last two lines cause sometimes I have issues when I use statements such as "something and not something_else". I dunno what's up but I think there's something funky in the grammer with regards to putting And right next to Not. The Parenthesis is a workaround for this.
Back to top
View user's profile Send private message Visit poster's website AIM Address
R.Legault



Joined: 24 Feb 2007
Posts: 111

Digg It
PostPosted: Thu Mar 22, 2007 3:21 am    Post subject:

It will only releases the key once the condition becomes false. However if you were to do something like:

press(Insert)
wait 50ms
release(Insert)
wait 50ms

Then you would get rapid fire on/off.

Let me know if you find a game where holding a button down using this method doesn't work. (That is when there is no wait after release)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group