ID:142498
 
Code:
            DblClick()
var/icon/I = new(usr.icon)
for(var/obj/E in usr.overlays)
E.icon = turn(E.icon,(90))
I.Turn(90)
usr.icon = I


Problem description:
Well we want it so when you double click a bomb it turns the mob and its overlays, since there are equip ables... We got it to turn the mobs icon but the overlays just aren't working, could anyone help me out? Of course this would happen four times.
Yes we really need some help, we have tried a lot of diffrent things
Nategrant wrote:
for(var/obj/E in usr.overlays)
E.icon = turn(E.icon,(90))

While this wouldn't work because you are searching for /objs in the overlays list but there are none, generally changing and and handling the overlays themselves once they're in the list is very limited and the little you can do is undocumented. For these kind of things you rebuild the overlays when you change them. This means you need to keep track of the overlays a mob has on, so you can recreate them later, this time after being turn()ed.
In response to Kaioken
So would I have to create another list of overlays or can i not change a entire list?
In response to Oasiscircle
The thing about the overlays list is that it's a special list, a lot about it is handled internally. It's damn-near impossible to really interact with it in any helpful means. Your best bet is indeed creating your own list and building the overlays list up based on the contents of that list.

mob
var/list/my_overlays = list()
proc/UpdateOverlays()
overlays = list() // Clear out the overlays list.
for(var/obj/O in my_overlays)
overlays += O


Now just call that when you need to change overlays and just add the objects in question to my_overlays, that way you can directly access the object and munipulate it.
In response to Nadrew
we now have
            DblClick()
var/icon/I = new(usr.icon)
for(var/obj/E in usr.my_overlays)
E.icon = turn(E.icon,(90))
usr.UpdateOverlays()
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(3)
E.icon = turn(E.icon,(90))
usr.UpdateOverlays()
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(3)
E.icon = turn(E.icon,(90))
usr.UpdateOverlays()
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(3)
E.icon = turn(E.icon,(90))
usr.UpdateOverlays()
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(3)

First it only works if something is equipped, second is it produces a huge amount of lag
In response to Nategrant
The problem now is that you're doing a massive amount of processing inside of a loop; you're not only turning the icons in question but you're doing the entire thing for every object in my_overlays, which is going to generate some pretty heavy overhead -- it also accounts for the first problem you mentioned, since if my_overlays is empty nothing happens. You need to move the general operations like usr.icon = I outside of the loop and then place the loop below them (but before you sleep() next). The most ideal method is making another proc to handle the loop for you.
mob
proc/TurnOverlays(angle)
for(var/obj/E in my_overlays)
E.icon = turn(E.icon,90)


Now inside of your DblClick you could do something like this:
I.Turn(90)
usr.icon = I
usr.UpdateOverlays()
usr.TurnOverlays(90)
sleep(3)
// Etc... etc...


Now, there are plenty of even more efficient ways of doing this like making the entire contents of DblClick() a proc, and even making the I.Turn(90) stuff into its own proc. You should also be aware that icon operations tend to be a little CPU intensive, so you may want to consider generating the icons you need inside of New() and storing them in variables so that you can cut the icon operations down from many to one for each needed Turn() call.
In response to Nadrew
It works just extreme lag

            DblClick()
var/icon/I = new(usr.icon)
I.Turn(90)
usr.icon = I
usr.TurnOverlays(90)
usr.UpdateOverlays()
step(usr,usr.dir)
sleep(3)
I.Turn(90)
usr.icon = I
usr.TurnOverlays(90)
usr.UpdateOverlays()
step(usr,usr.dir)
sleep(3)
I.Turn(90)
usr.icon = I
usr.TurnOverlays(90)
usr.UpdateOverlays()
step(usr,usr.dir)
sleep(3)
I.Turn(90)
usr.icon = I
usr.TurnOverlays(90)
usr.UpdateOverlays()
step(usr,usr.dir)
sleep(3)

mob
var/list/my_overlays = list()
proc/UpdateOverlays()
overlays = list() // Clear out the overlays list.
for(var/obj/O in my_overlays)
overlays += O
proc/TurnOverlays(angle)
for(var/obj/E in my_overlays)
E.icon = turn(E.icon,90)
In response to Nategrant
Narrowed it down has extreme lag here:
    proc/TurnOverlays(angle)
for(var/obj/E in my_overlays)
E.icon = turn(E.icon,90)

Nadrew: Right, icon operations are slow -- ideally you want to generate all of that stuff and store it in a variable so you don't keep having to use turn().

Thats I guess what I need to do, how could I do that though?
Thanks.
In response to Nategrant
This is what I could think up right now. It's late, though, so there might be a better method. I think I hurt my head trying to think of a linked list whose every element is a linked circular list.

var/list/spincache = list()

mob/proc/breakdance(var/speed = 3)
for(var/obj/E in my_overlays)
spawn()
var/oldicon = E.icon
var/list/L = getspins(oldicon)
for(var/v = 1, v <= 3, v++)
E.icon = L[v]
sleep(speed)
E.icon = oldicon

proc/getspins(var/icon/i)
if( !(i in spincache) )
var/list/L = list()
for(var/v = 90, v <= 270, v += 90)
L += i.Turn(v)
spincache[i] = L
return spincache[i]
In response to Garthor
I tried putting this in and not really sure how it works, but I got two errors:
runtime error: Cannot execute null.Turn().
proc name: getspins (/proc/getspins)
source file: quips.dm,17
usr: Nategrant (/mob)
src: null
call stack:
getspins('armour.dmi')
Nategrant (/mob): breakdance(3)
runtime error: cannot read from list
proc name: breakdance (/mob/proc/breakdance)
source file: quips.dm,9
usr: Nategrant (/mob)
src: Nategrant (/mob)
call stack:
Nategrant (/mob): breakdance(3)
In response to Nategrant
See this, people? This is why you don't copypasta code we give you on the forums.
In response to Darkmag1c1an11
Shut up, I bought a membership. Be nice to me at least for that. Also i'm just putting it in there to learn how it works, not for the game.
In response to Nategrant
Nategrant wrote:
Shut up, I bought a membership. Be nice to me at least for that. Also i'm just putting it in there to learn how it works, not for the game.
lol.

Not even the BYOND staff gives a frick.
I'm sorry to say but, that one membership isnt gonna make the difference of home or no home for the staff.
In response to Eternity Productions
I just need some help and now people are starting to flame up my post, do so elsewhere!
In response to Nategrant
Okay, I wrote that too late at night and so it's broken. Here's one that works:

mob/proc/breakdance(var/speed = 3)
for(var/obj/E in my_overlays)
spawn()
var/list/L = getspins(E.icon)
overlays -= E
var/image/newoverlay = image(icon = E.icon, icon_state = E.icon_state, layer = E.layer, dir = E.dir)
for(var/v = 1, v <= 3, v++)
newoverlay.icon = L[v]
overlays += newoverlay
sleep(speed)
overlays -= newoverlay
overlays += E

proc/getspins(var/icon/i)
if( !(i in spincache) )
var/list/L = list()
for(var/v = 90, v <= 270, v += 90)
L += turn(i, v)
spincache[i] = L
return spincache[i]
In response to Garthor
I know have
var/list/spincache = list()

mob/proc/breakdance(var/speed = 3)
var/icon/I = new(usr.icon)
for(var/obj/E in my_overlays)
spawn()
var/list/L = getspins(E.icon)
overlays -= E
var/image/newoverlay = image(icon = E.icon, icon_state = E.icon_state, layer = E.layer, dir = E.dir)
for(var/v = 1, v <= 3, v++)
newoverlay.icon = L[v]
overlays += newoverlay
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(speed)
overlays -= newoverlay
overlays += E
I.Turn(90)
usr.icon = I
step(usr,usr.dir)

proc/getspins(var/icon/i)
if( !(i in spincache) )
var/list/L = list()
for(var/v = 90, v <= 270, v += 90)
L += turn(i, v)
spincache[i] = L
return spincache[i]

The only problem is, when I call it without something equipped it dosn't work... how would I fix that?
In response to Nategrant
You have to move anything that isn't related to the overlays themselves spinning outside the for() loop. spawn() will also probably have to be used.
In response to Nategrant
Just so you know, by caching icons you're exchanging speed for memory, which might not be ideal if you're short on resources. How about cleaning the spincache list once in a while?
In response to Garthor
var/list/spincache = list()

mob/proc/breakdance(var/speed = 3)
var/icon/I = new(usr.icon)
var/obj/G = new(my_overlays)
if(!(G in my_overlays))
for(var/obj/E in my_overlays)
spawn()
var/list/L = getspins(E.icon)
overlays -= E
var/image/newoverlay = image(icon = E.icon, icon_state = E.icon_state, layer = E.layer, dir = E.dir)
for(var/v = 1, v <= 3, v++)
newoverlay.icon = L[v]
overlays += newoverlay
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
sleep(speed)
overlays -= newoverlay
overlays += E
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
usr.rolling = 0
world << "0" // between here and next line....
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
usr.rolling = 0
sleep(3)
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
usr.rolling = 0
sleep(3)
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
usr.rolling = 0
sleep(3)
I.Turn(90)
usr.icon = I
step(usr,usr.dir)
usr.rolling = 0
sleep(3)
rolling = 0
world << "1"
return

I think I know what you mean here is the closest I can get it...
The only problem is where I typed between there and the next I need some sort of return to make it stop going, but if I put a return anywhere it either only calls the for once or doesn't work at all. What now?
Page: 1 2