[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  struggling with variables and math...

struggling with variables and math...

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Lilbopeep   USA  (42 posts)  [Biography] bio
Date Tue 08 Nov 2011 06:36 AM (UTC)

Amended on Tue 08 Nov 2011 06:37 AM (UTC) by Lilbopeep

Message
this is what I have so far:


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="\'Will you hit\, stay\, or double down\?\'"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>local DealHand
local MyHand

DealHand = GetVariable("deal_hand")
MyHand = GetVariable("my_hand")

if DealHand == Ace then
SetVariable("deal_hand", "1")
else
if DealHand == Two then
SetVariable("deal_hand", "2")
else
if DealHand == Three then
SetVariable("deal_hand", "3")
else
if DealHand == Four then
SetVariable("deal_hand", "4")
else
if DealHand == Five then
SetVariable("deal_hand", "5")
else
if DealHand == Six then
SetVariable("deal_hand", "6")
else
if DealHand == Seven then
SetVariable("deal_hand", "7")
else
if DealHand == Eight then
SetVariable("deal_hand", "8")
else
if DealHand == Nine then
SetVariable("deal_hand", "9")
else
if DealHand == Ten then
SetVariable("deal_hand", "10")
else
if DealHand == Jack then
SetVariable("deal_hand", "10")
else
if DealHand == Queen then
SetVariable("deal_hand", "10")
else
if DealHand == King then
SetVariable("deal_hand", "10")
end
end
end
end
end
end
end
end
end
end
end
end
end
DealHand = GetVariable("deal_hand")
MyHand = GetVariable("my_hand")
ColourNote ("Black", "Blue", "DealHand is (" .. DealHand .. ")")
ColourNote ("Black", "Blue", "MyHand is (" .. MyHand .. ")")
</send>
  </trigger>
  <trigger
   enabled="y"
   match="Your current total is\: *(\d+)*$"
   regexp="y"
   send_to="9"
   sequence="100"
   variable="my_hand"
  >
  <send>%1</send>
  </trigger>
  <trigger
   enabled="y"
   match="A blackjack dealer deals (a|an) (.*?) of (.*?) face up to himself\.$"
   regexp="y"
   send_to="9"
   sequence="100"
   variable="deal_hand"
  >
  <send>%2</send>
  </trigger>
</triggers>


Basically, there are a few things I know I need to clean up, but im just trying to see results..

Right now, I get colour notes telling me my hand correctly, and it even tells me the card the dealer has, but it isn't actually 'updating' the variable.

Also, when I tried a different approach it would give me errors relating to doing math on a string or something.

Id like to get them both to numbers that I can do things with to determine how I should proceed at the table.

,.~`'~.,Dance Magic Dance,.~`'~.,
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Tue 08 Nov 2011 06:59 AM (UTC)

Amended on Tue 08 Nov 2011 07:01 AM (UTC) by Fiendish

Message
Ace, Two, Three, etc need to be strings. "Ace", "Two", "Three", and so on.

Also, holy cow. Make all those elses and ifs into elseifs so that you can collapse that crazy chain of ends down to only one.

use tonumber() to convert a numeric string to the equivalent number

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Tue 08 Nov 2011 08:23 AM (UTC)

Amended on Tue 08 Nov 2011 08:29 AM (UTC) by Twisol

Message
Fiendish said:

Ace, Two, Three, etc need to be strings. "Ace", "Two", "Three", and so on.

Also, holy cow. Make all those elses and ifs into elseifs so that you can collapse that crazy chain of ends down to only one.


Heavily condensed:
local DealHand = GetVariable("deal_hand")
local MyHand = GetVariable("my_hand")

local cardnums = {
  Ace = 1,
  Two = 2,
  Three = 3,
  Four = 4,
  Five = 5,
  Six = 6,
  Seven = 7,
  Eight = 8,
  Nine = 9,
  Ten = 10,
  Jack = 10,
  Queen = 10,
  King = 10,
}

if cardnums[DealHand] then
  DealHand = cardnums[DealHand]
  SetVariable("deal_hand", DealHand)
end

ColourNote ("Black", "Blue", "DealHand is (" .. DealHand .. ")")
ColourNote ("Black", "Blue", "MyHand is (" .. MyHand .. ")")


[EDIT]: (If you're -really- curious and don't want your head to explode from my late-night ramblings) - One might wonder why I didn't quote the keys of that table, when Fiendish just said "Ace", "Two", etc. needed to be quoted. Long story short: if you're putting something on the right into something on the left, the thing on the left is probably a variable, and the variable name isn't quoted. Since we're defining these variables within a table, though, we can use a string to get at those variables.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Lilbopeep   USA  (42 posts)  [Biography] bio
Date Reply #3 on Wed 09 Nov 2011 08:56 AM (UTC)
Message
Ah, this is making a bit more sense now.

Thanks for the help!

,.~`'~.,Dance Magic Dance,.~`'~.,
[Go to top] top

Posted by Lilbopeep   USA  (42 posts)  [Biography] bio
Date Reply #4 on Fri 11 Nov 2011 02:58 AM (UTC)
Message
While hands of blackjack are being played, Id like to keep track of how many hands i've won/lost/drawn this session, as well as keep track of how much money im up or down.


if GetVariable("Lost") == nil then
SetVariable("Lost", tonumber(1))
else
Lost = GetVariable("Lost") +1
Colournote ("Black", "Blue", "You've lost (" .. Lost .. ") hands this session")
end



The problem is it will recognize that it's nil and set it to one, but it doesn't seem to keep 'counting', it just goes to two and then stops.. what am I missing here?

,.~`'~.,Dance Magic Dance,.~`'~.,
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Fri 11 Nov 2011 03:05 AM (UTC)
Message
tonumber(1) is silly, because 1 is already a number.

GetVariable always returns a string, so you need to do Lost = tonumber(GetVariable("Lost")) +1

You never set Lost again after incrementing it.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Lilbopeep   USA  (42 posts)  [Biography] bio
Date Reply #6 on Fri 11 Nov 2011 03:20 AM (UTC)
Message

if GetVariable("Lost") == nil then
Lost = 1
ColourNote ("Black", "Blue", "Lost set to 1")
else
Lost = tonumber(GetVariable("Lost")) + 1
ColourNote ("Black", "Blue", "You have lost (" .. Lost .. ") hands this session.")
end


it's still saying, "You have lost 2 hands this session." every time I lose?


,.~`'~.,Dance Magic Dance,.~`'~.,
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 11 Nov 2011 03:26 AM (UTC)
Message
You need to set the variable back. eg.



if GetVariable("Lost") == nil then
  SetVariable("Lost", "1")
else
  Lost = tonumber (GetVariable("Lost")) + 1
  SetVariable ("Lost", Lost)
  Colournote ("Black", "Blue", "You've lost (" .. Lost .. ") hands this session")
end


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,423 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]