ID:140045
 
Code:
obj/Pickup
Ammo
var
ammo=0
mammo=0
pistol10mmAmmo
name="Handgun Ammo"
icon='SGammo.dmi'
icon_state="10mm_ammo"
ammo=rand(1, 20)
mammo=1000000


Problem description:

Small_Gun ammo.dm:10:error: : expected a constant expression
rand() would determine its return value at run time. So you can't go ahead and define an atom when one of its variables isn't known until the world is run. Sooo, make that variable determined when the world is run.

obj/Pickup
Ammo
var
ammo=0
mammo=0
pistol10mmAmmo
name="Handgun Ammo"
icon='SGammo.dmi'
icon_state="10mm_ammo"
mammo=1000000
New()
..()
ammo=rand(1, 20)
You can't give a variable a non-constant value at compile-time. If you want to use rand() to set the variable you'll have to do is inside of a procedure such as Login() or New().
If you're getting this kind of error, then it might help to read this article. It was written specifically to explain where you can use procs like rand, and where you can't. It's kinda a long article, but if you take 10 minutes to read it, then you'll save yourself hours of wrestling with DM trying to get it to do what you want, and you'll be a much better programmer.
In response to Murrawhip
just do this
obj/Pickup
Ammo
var/rand1=rand(1,20) //<---- add this variable
var
ammo=0
mammo=0
pistol10mmAmmo
name="Handgun Ammo"
icon='SGammo.dmi'
icon_state="10mm_ammo"
mammo=1000000
New()
..()
ammo=rand1 //<--change the rand(1,20) to this
In response to The Developer
The Developer wrote:
just do this
obj/Pickup
Ammo
var/rand1=rand(1,20) //<---- add this variable
var
ammo=0
mammo=0
pistol10mmAmmo
name="Handgun Ammo"
icon='SGammo.dmi'
icon_state="10mm_ammo"
mammo=1000000
New()
..()
ammo=rand1 //<--change the rand(1,20) to this

You change my solution to use two variables instead of one for what reason?
You also still are defining the var as a non-constant, which was the OP's problem in the first place.
In response to The Developer
@ The Developer

You really don't know what you are talking about most of the time.
I would suggest to stop trying to help people, especially by using code examples since they have shown to be quite useless and poorly written.