generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Percentage Chance Module not werkin

Previous Thread :: Next Thread 
cxcharlie is not online. 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 is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 09:27 PM
bump
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
25 Jun 2015 09:29 PM
table.insert(module.Tokens, id) pl0x
Report Abuse
cxcharlie is not online. 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 is not online. 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 is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 09:56 PM
any boody~~
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 09:59 PM
*smashes head onto keyboard
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 10:09 PM
*keyboard breaks
*smashes head into lcd screen
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 10:13 PM
*lcd breaks
*smashes head on table
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 10:19 PM
*breaks head
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 10:48 PM
*ambulance arrives
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 10:53 PM
ed chuodsyfego34 34i
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
25 Jun 2015 11:52 PM
aa5yh54w 45 54h 4h etygh
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
26 Jun 2015 12:18 AM
48 views one reply
hoorary for scripting forum
Report Abuse
ImperialOutcast is not online. ImperialOutcast
Joined: 24 Nov 2009
Total Posts: 12054
26 Jun 2015 12:28 AM
Let's see Module.Table?


Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
26 Jun 2015 12:51 AM
Err what are you talking about?
Report Abuse
ImperialOutcast is not online. ImperialOutcast
Joined: 24 Nov 2009
Total Posts: 12054
26 Jun 2015 12:53 AM
Err I don't know


module.Tokens = {}


Got that? I'm looking for this!!!
Report Abuse
cxcharlie is not online. 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
ImperialOutcast is not online. ImperialOutcast
Joined: 24 Nov 2009
Total Posts: 12054
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image