chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:31 PM |
So how is this possible
---Code:
print(type(self.Dna.Genes[1]), self.Dna.Genes[1]) self.MaxSpeed = MathLib:Map(self.Dna.Genes[1], 0, 1, 15, 0)
function MathLib.Map(Value, Low1, Low2, High1, High2) return High1 + (High2 - High1) * (Value - Low1) / (Low2 - Value) end
---Output:
number 1 The error is saying value is a table value when it's obviously not
|
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
| |
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:35 PM |
self.Dna.Genes[1] = math.random(0, 1)
The error still occurs saying its a table wether I give it a string, a number, or anything else |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:37 PM |
| Do you understand why this doesn't make any sense? Is this a common problem? |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:41 PM |
Here is the entire program if for some reason you need it, I'm running on codea and iPad app.
-- Ecosystem
function setup() Creatures = {} CreatureAmount = 20 for Index = 1, CreatureAmount do Creatures[Index] = Creature() end end
function draw() background(255, 255, 255, 255) for _, Creature in next, Creatures do Creature.Update() Creature.Display() end end
Creature = class()
function Creature:init() self.Color = color(math.random(1, 255), math.random(1, 255), math.random(1, 255)) self.Offset = vec2(math.random(-10000, 10000), math.random(-10000, 10000)) self.Position = vec2(math.random(1, WIDTH), math.random(1, HEIGHT)) self.Dna = Dna() print(type(self.Dna.Genes[1]), self.Dna.Genes[1]) self.MaxSpeed = MathLib:Map(self.Dna.Genes[1], 0, 1, 15, 0) self.Radius = math.random(15, 100) self.Health = 200 function self.Update() local VelocityX = MathLib.Map(noise(self.Offset.x), 0, 1, -self.MaxSpeed, self.MaxSpeed) local VelocityY = MathLib.Map(noise(self.Offset.y), 0, 1, -self.MaxSpeed, self.MaxSpeed) local Velocity = vec2(VelocityX, VelocityY) self.Offset = self.Offset - vec2(0.01, 0.01) self.Position = self.Position + Velocity self.Health = self.Health - 1 end function self.Display() stroke(self.Color) fill(self.Color) ellipse(self.Position.x, self.Position.y, self.Radius) end function self.Dead() if self.Health <= 0 then return true else return false end end function self.Eat() local Foods = Foods:Fetch() for _, Food in next, Foods do if self.Position:dist(Food) < self.Radius then self.Health = self.Health + 100 end end end end
Dna = class()
function Dna:init() self.Genes = {math.random(0, 1)} end
MathLib = class()
function MathLib.Map(Value, Low1, Low2, High1, High2) return High1 + (High2 - High1) * (Value - Low1) / (Low2 - Value) end |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 07 Dec 2015 09:45 PM |
| that '[1]' why is that there, what is its necessity being there if you are using math.random(); because otherwise of course it would error, because you're trying to print the first value of something that isn't a table |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 07 Dec 2015 09:45 PM |
| that isn't a table or within the table* |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:47 PM |
| Yes it's nessacary, how else would I index the first element in a table? |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 07 Dec 2015 09:47 PM |
| oh you put {math.random(0,1)} didn't see your post |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 09:49 PM |
| I don't think you understand, even if I give that parameter a nil value it still says it's a table |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 07 Dec 2015 10:07 PM |
| Bump, see you guys in the morning |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2015 10:35 PM |
| it's because you're using colon syntax for whatever reason when calling MathLib.Map, so MathLib is automatically passed as the first parameter, "Value" |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2015 10:36 PM |
e.g
local MathLibrary = {}
function MathLibrary.Map(example) print(example) end
MathLibrary.Map(5) MathLibrary:Map()
OUTPUTS: 5 table: 0x1e8c4730 |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2015 10:37 PM |
well if its trying to say its a table why not check whats in that said table? print(type(self.Dna.Genes[1][1]), self.Dna.Genes[1][1])
http://www.roblox.com/ITS-FREE-item?id=130771265&rbxp=8320118 |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2015 10:38 PM |
| m8s what I said is the problem |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2015 10:39 PM |
I had this thread open for awhile so I did not see that you posted until I posted
http://www.roblox.com/ITS-FREE-item?id=130771265&rbxp=8320118 |
|
|
| Report Abuse |
|
|