cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 09:18 PM |
I made a very simple percentage chance module, where given an "id", it will insert it "x" amount of times into a table.
When I want it to choose a value from all of the given id's I just get a math.random(#table), but something gets messed up along the way.
Example: "module.InsertTokens(5,'a') module.RemoveId('a') print(#module.Tokens)" >2 --should be 0 --why does it return 2?? D:
function module.InsertTokens(amount, id) --this function works fine, you prob don't need to look through it for i = 1, amount do --amount times print'inserting' module.Tokens[#module.Tokens+1]=id end end
function module.RemoveId(id) for index, v in pairs(module.Tokens) do if v == id then print'removing' --if I look at how many times I've printed this --and how many times I've inserted a token, they don't match table.remove(module.Tokens, index) end end end
|
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
|
| 25 Jun 2015 09:29 PM |
| table.insert(module.Tokens, id) pl0x |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 09:40 PM |
No, I already tried that. I don't use table.insert because it's slower |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 09:45 PM |
| this scropt so simple, why et no werk D:::: |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 09:59 PM |
| *smashes head onto keyboard |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 10:09 PM |
*keyboard breaks *smashes head into lcd screen |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 25 Jun 2015 10:13 PM |
*lcd breaks *smashes head on table |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 26 Jun 2015 12:18 AM |
48 views one reply hoorary for scripting forum |
|
|
| Report Abuse |
|
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 26 Jun 2015 12:51 AM |
| Err what are you talking about? |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2015 12:53 AM |
Err I don't know
module.Tokens = {}
Got that? I'm looking for this!!! |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 26 Jun 2015 12:58 AM |
| I have that in my code, just didn't show it |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2015 01:01 AM |
This is really inefficient by the way. I highly suggest you rethink the process
module = {} module.Tokens = {}
module.AddToken = function(Ammount, ID) for i = 1,Ammount do table.insert(module.Tokens, ID) end end
module.RemoveToken = function(ID) for index,v in pairs(module.Tokens) do if v == ID then table.remove(module.Tokens, index) end end end
--Other Script
print(math.random(#module.Tokens))
|
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 26 Jun 2015 01:50 PM |
I already noticed that, but I couldn't think up of another way to make a more accurate calculation of random based percentage. Also, I already have a part that does that, just not included in the code (for your last line).
|
|
|
| Report Abuse |
|
|