ID:147044
 
for(var/turf/T in world)
var/randomization = rand(0,99)
if(istype(T, /turf/floor/wood))
if(randomization == 0)
var/turf/trap/spike/G = new(T.loc)


This is the section of code where the problem occurs. When I run the verb in the game, I get this error:

runtime error: bad loc
proc name: Begin Game (/mob/verb/Begin_Game)
usr: MyName (/mob/player)
src: MyName (/mob/player)
call stack:
MyName (/mob/player): Begin Game()

...and I don't understand how to fix it. Thanks for any help in advance.
Gynax wrote:
for(var/turf/T in world)
> var/randomization = rand(0,99)
> if(istype(T, /turf/floor/wood))
> if(randomization == 0)
> var/turf/trap/spike/G = new(T.loc)

This is the section of code where the problem occurs. When I run the verb in the game, I get this error:

runtime error: bad loc
proc name: Begin Game (/mob/verb/Begin_Game)
usr: MyName (/mob/player)
src: MyName (/mob/player)
call stack:
MyName (/mob/player): Begin Game()

...and I don't understand how to fix it. Thanks for any help in advance.

Heh,First of all your error is in the Begin Game verb.
In response to CodingSkillz2
Yep, and I just posted the contents of mob/verb/Begin_Game()
In response to Gynax
Where?
In response to CodingSkillz2
It's the code that you quoted.
In response to Gynax
Did you fix it? If not post the verb.
In response to CodingSkillz2
mob
verb
Begin_Game()
set category = "Actions"
for(var/turf/T in world)
var/randomization = rand(0,99)
if(istype(T, /turf/floor/wood))
if(randomization == 0)
var/obj/trap/spike/G = new(T.loc)

I already did, but there you go again...
In response to Gynax
You aren't using new right I think....
In response to Gynax
You didn't put mob verb so I thought it was a proc =p oh well lets stop spamming forums shall we?
In response to CodingSkillz2
How could I fix that problem, then?
In response to N1ghtW1ng
Don't know if that's it but that does look funky..Everything else looks fine though..
In response to Gynax
If your trying to make random turfs appear randomly, you need to do rand(1,world.maxx) rand(1,world.maxy) and save it in a variable, and then use the new(locate(var1,var2,T.z))
In response to N1ghtW1ng
And if I only want it to appear on a certain type of turf?
The argument for new needs to be another turf. You specify a turf, and the new one takes its place. So you want new(T), not new(T.loc).

Also note that the new turf will take the place of the old one, not be made over top of it. Only one turf can be in any one tile. If you want the graphic for the old turf to stay, you will want to get a reference to its icon then add that icon to the new turf's underlays.
mob/verb/NewTurf()
var/turf/T=loc
var/icon/I=T.icon
var/turf/different_turf/T2=new(T)
T2.underlays+=I

That is how you would keep the graphic of the old one as an underlay of the new turf.
In response to Loduwijk
Aahh... thank you.