for loop and timers

Forget about the loop xD

I have this piece of code :
[lua]

timer.Create( “my_timer”, 0.5, Melonwace_spawn_melons, CreateMelon())

function CreateMelon()

Melonwave_use_vector = Melonwave_starting_vector
Melonwave_use_vector.y = Melonwave_use_vector.y + math.random( 5, 15 )

melon=ents.Create("prop_physics")
melon:SetModel("models/props_junk/watermelon01.mdl")
melon:SetPos(Melonwave_use_vector)
melon:Spawn()

end
[/lua]

only it gives me some errors :

Timer Error: attempt to call a nil value
Hook ‘CheckTimers’ Failed: includes/modules/timer.lua:164: attempt to compare nil with number

You shouldn’t call the function in the timer, you just pass the function to it. Your timer should look like this:
[lua]timer.Create( “my_timer”, 0.5, 0, CreateMelon)[/lua]

Thanks will try that out now.

Edit :

It fixed the time error but im still getting this :

Hook ‘CheckTimers’ Failed: includes/modules/timer.lua:164: attempt to compare nil with number

And it creates 1 melon but it doesn’t fall or anything it just floats there with no physics what so ever

Have you set Melonwace_spawn_melons to a value? Because it’s saying it’s nil, ie. not set.

Lol thanks it was a grammar thingie It was supposed to be Melonwave_spawn_melons

[editline]02:14PM[/editline]

Last question xD
[lua]
function CreateMelon()

Melonwave_use_vector = Melonwave_starting_vector
Melonwave_use_vector.y = Melonwave_use_vector.y + math.random( -15, 15 )

melon=ents.Create("prop_physics")
melon:SetModel("models/props_junk/watermelon01.mdl")
melon:SetPos(Melonwave_use_vector)
melon:Spawn()

end
[/lua]

It just floats in mid air it doesnt have any physics and I tried Activate()

You probably put it in the wrong place, place Activate in your script and show us the new script.

[lua]
function CreateMelon()

Melonwave_use_vector = Melonwave_starting_vector
Melonwave_use_vector.y = Melonwave_use_vector.y + math.random( -15, 15 )

melon=ents.Create("prop_physics")
melon:SetModel("models/props_junk/watermelon01.mdl")
melon:SetPos(Melonwave_use_vector)
melon:Spawn()

melon:Activate()

end
[/lua]

-snip-

You doing this clientside or serverside?

Serverside, I’ve put it in this map :

C:\Program Files\Steam\steamapps\quincy18\garrysmod\garrysmod\lua\autorun

move to C:\Program Files\Steam\steamapps\quincy18\garrysmod\garrysmod\lua\autorun\server

Thanks it worked