Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ complex maths thing

complex maths thing

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


Pages: 1  2 

Posted by Humiliation   (12 posts)  Bio
Date Reply #15 on Sat 14 Apr 2007 11:14 AM (UTC)
Message
SORTED. A couple of the signs were were wrong (> instead of < - instead of +). works like a dream now
Top

Posted by Isthiriel   (113 posts)  Bio
Date Reply #16 on Sat 14 Apr 2007 02:29 PM (UTC)
Message
Part of your problem is that Shaun Biggs in his first post skipped over some of your explanation when he was writing the code :(

Quote:
And just to make it even more complicated i forgot to add after multiplying it by 300 if it is above 75 we minus 75 from it then minus that number from 75 and if it is below we minus it from 75 then add 75. And then round it to the nearest whole number. If that makes sense...


Ok, breaking this up into pseudo-code:


temp1 is our number after multiplying by 300

if temp1 > 75:
  temp2 = temp1 - 75
  temp3 = 75 - temp2

if temp1 < 75:
  temp2 = 75 - temp1
  temp3 = temp2 + 75

tempf = round(temp3)

Note that in the case of temp1 == 75, nothing is done.

If we examine the maths a bit more, it turns out that if temp1 > 75 then temp3 = 75 - (temp1 - 75) => temp3 = 75 - temp1 + 75 => temp3 = 150 - temp1.

We already know the temp1 < 75 case devolves to temp3 = 150 - temp1 from one of the earlier posts, so out pseudocode should actually be:

temp1 is our number after multiplying by 300
tempf = round(150 - temp1)


HTH.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #17 on Sat 14 Apr 2007 06:25 PM (UTC)
Message
ok, now that I've had a bit of time to think about this and I don't have any alcohol in my system...

vars = { var1="%1", var2="%2", var3="%3", var4="%4" }
divisor = 300 / ( "%1" + "%2" + "%3" + "%4" )
for i,v in pairs(vars) do
  temp = v * divisor
  if temp > 75 then
    temp = (temp - 75) - 75
  else
    if temp < 75 then
      temp = (75 - temp ) + 75
    end
  end
  if temp < 0 then
    temp = math.ceil( temp - 0.5 )
  else
    temp = math.floor( temp + 0.5 )
  end
  SetVariable( i, temp )
end -- loop


The main issue with the actual math is that how you tried stating what the logic is just is way too ambiguous. Seems like one of those things that are easier to think about than to explain. The best way to start explaining in this situation is to break it down into smaller chunks instead of trying to get the whole process out in one statement with no punctuation. Also breaking it down into sections that you can easily refer back to would help.
Quote:
And just to make it even more complicated i forgot to add after multiplying it by 300 if it is above 75 we minus 75 from it then minus that number from 75 and if it is below we minus it from 75 then add 75. And then round it to the nearest whole number. If that makes sense...

Could be easier to read in this format:
1) sum = sum of v1,v2,v3, and v4
2) temp = var / sum * 300
3) if temp at stage 2 is ___ then temp should be temp - 75 etc.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #18 on Sat 14 Apr 2007 08:40 PM (UTC)
Message
This thread does remind of a question I had earlier. Is there a nice easy way to get Lua to have a table of all the wildcards in an alias or trigger without having to pass it to a script in the world file? That would make a few of my scripts a bit easier to deal with.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #19 on Sat 14 Apr 2007 09:13 PM (UTC)
Message
Check out GetTriggerWildcard. I'm not sure you can tell how many wildcards there are, short of working your way through the list (1, 2, 3 etc.) until it returns an empty string.

http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Isthiriel   (113 posts)  Bio
Date Reply #20 on Sun 15 Apr 2007 06:54 AM (UTC)
Message
Quote:
if temp > 75 then
  temp = (temp - 75) - 75
else

If we simplify this we get temp = temp - 150. Since temp can presumably be 76, we end up with a negative again.

Seriously, the if checks are redundant. temp = 150 - temp is what he's looking for based on the explanation he gave.

It helps if you replace the word "minus" with "subtract" as appropriate in the explanation, ie: if it is above 75 we subtract 75 from it (temp) then subtract that number (temp - 75) from 75 (75 - (temp - 75) = 150 - temp) and if it is below ( if temp < 75) we subtract it from 75 (75 - temp) then add 75 ((75 - temp) + 75 = 150 - temp).

Humiliation, how did you come up with this math in the first place?
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #21 on Sun 15 Apr 2007 08:59 AM (UTC)

Amended on Sun 15 Apr 2007 09:04 AM (UTC) by Shaun Biggs

Message
I'm pretty sure I get the basic idea about what the math is supposed to do. I just don't know where the difference between how Humiliation has in in his head and how we have it in our head is. I think it's supposed to change the value to be closer to 75 than it originally is, similar to how tiered damage reduction works after a certain cap in a diku mud.

if damage > 80 then
damage = ( (damage - 80) * 0.75 ) + 80

or something similar to that effect. That way the higher damage is reduced a bit to cut back on everyone one hitting each other, and you still have the higher damage doing more damage as it increases.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Isthiriel   (113 posts)  Bio
Date Reply #22 on Tue 17 Apr 2007 02:52 AM (UTC)
Message
Except that the larger the individual skill numbers are, the smaller the resultant number is.

temp = 300 * (0.5 - (skill / sum_skills))

Which means either that "high skill" is actually represented by a small number OR the result number is actually something he wants to minimize (chance to miss?).

Since it is relativized (by the / sum_skills), having all your skills equal will get the same end results irrespective of the actual skill values. AND if any one skill makes up more than half of the total skills (ie 40, 10, 10, 10) it will go negative again.
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.


61,747 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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

Go to topic:           Search the forum


[Go to top] top

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