ID:145926
 
obj
buttontrain
name = "Shuttle"
icon = 'icon.dmi'
icon_state = "off"
density = 1
Click()
if(src in oview(1))
if(on == 0)
if(shuttle1 == 1)
on = 1
for(var/obj/buttontrain/O in world)
O:icon_state = "on"
for(var/obj/train/O in world)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
O:y += 1
sleep(1)
for(var/obj/buttontrain/O in world)
O:icon_state = "off"
on = 0
shuttle1 = 0
else
on = 1
for(var/obj/buttontrain/O in world)
O:icon_state = "on"
for(var/obj/train/O in world)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
O:y -= 1
sleep(1)
for(var/obj/buttontrain/O in world)
O:icon_state = "off"
on = 0
shuttle1 = 1


Ok i coded a train tile in my game and placed it in a 3 by 7 square and made a button to move it up and down, but instead of all the blocks moving at the same time it moved them one at a time,creating a jigsaw effect where the tran is taken apart piece by piece and placing them in the new location, does anybody know how to make it move all the train objs in world at one time rather than it cycling through them.

no one know?
In response to Contact
Bump
In response to Contact
Arr.
Please wait 24 hours before bumping. This is a forum, not a chatroom.


You have colon abuse and you're using ==0 and ==1 for what I assume are boolean vars.
==1 is the same as var.
==0 is the same as !var.
In response to Artemio
thats nice but doesnt help.
for(var/obj/train/O in world)
O:y += 1
sleep(1)
O:y += 1
sleep(1)


You have the loop like that.
It goes through each part seperately within that loop, so it moves one part onece, then sleeps, then moves that same part again, and repeats that til its all the way across, then does the next part.
In response to Dever
yah it moves it up one piece at a time, what i mean is i have 3 pieces across, instead of all 3 pieces going up one space after another, one square goes up one space at a time till it reaches the end, then the next square till it gets there then the next square.
In response to Contact
for(var/obj/train/O in world)
O:y += 1
sleep(1)
O:y += 1
sleep(1)


Yes, from that, it would do that.

Try this,
for(var/w=0,w<14,w++)
for(var/obj/train o in world)
O:y+=1
sleep(1)

Something to that should work the way you want.

Of course replace the >> with tabs, I'm too lazy right now to write it all out correctly.
First off, take Artemio's advice about cleaning up the code. It might not help in the way you are looking for, but it does help.

It would make the thing easier to read and see exactly what is going on if you used a loop instead of the same two lines over and over again.

You might want to change the object's loc variable instead of its y variable. Also, if you want the train to stop for obstacles, or want to do any other special movement related actions, you'll want to use the Move function instead of altering loc directly.

Now, one way you could fix it to do what you are looking for is to use spawn on the loop's code block. If you don't understand what that does, look it up in the help file. Using spawn will allow the loop to continue on while the rest of the code block executes, allowing the entire loop to cycle through at once and have it working on all parts of the train simultaneously.
In response to Loduwijk
The problem he was having is not the moving at them exact same time, which even spawn won't accomplish, but the fact that he made the loop wrong to where one piece would go all the way across before the next one moved. You obvisouly didn't even fully read about his problem, or look at his code.
In response to Dever
Dever wrote:
The problem he was having is not the moving at the exact same time, which even spawn won't accomplish

Actually, spawn will accomplish it.

You obvisouly didn't even fully read about his problem, or look at his code.

I did both, and my solution works.
var/turf/T
for(var/obj/train/O in world)
spawn()
for(var/index = 1 to 10)
T = locate(O.x, O.y+1, O.z)
if(T) O.loc = T
sleep(1)

That will work just fine for exactly what he wants.

[edit]
Not only will it work, but in most cases it will probably work better as the function will not be bogged down by the movement of the train. It will be able to continue on its merry way and even return while the train continues to move.

Many bugs can sprout up when you oversleep a function and wonder why other functions, which are called after the current one from the current function's caller, are happening late or not at all.

In this case that isn't a problem, but it is always good to form good habits so they are second nature when you need them.
In response to Loduwijk
BUT, that wasn't the problem he was having, so your explantion had nothing to do with what he was asking.
In response to Dever
ive not written a code like that so im having difficulty understanding it.

        Click()
if(src in oview(1))
if(on == 0)
if(shuttle1 == 1)
on = 1
for(var/obj/buttontrain/O in world)
O:icon_state = "on"
for(var/w=0,w<14,w++)
for(var/obj/train o in world)
O:y+=1
sleep(1)
is that right?
In response to Dever
It appears you do not understand what my explanation was if you believe that. Please tell me, if I did not solve his problem then what exactly do you think my code is supposed to do?

He wanted the pieces to all move at once instead of each one making the full revolution one at a time. That is exactly what my suggestion does. If you cannot see that by reading it, test it out yourself in a testworld.
In response to Loduwijk
I never said it wouldn't work, but from what you said, you acted like the problem was that the pieces weren't moving at the 'exact' same time, and simply putting in a spawn would fix it.
In response to Dever
kool it works.
In response to Dever
Dever wrote:
I never said it wouldn't work

Delver wrote earlier:
your explantion had nothing to do with what he was asking.

Delver wrote:
but from what you said, you acted like the problem was that the pieces weren't moving at the 'exact' same time, and simply putting in a spawn would fix it.

Simply putting in a spawn would fix it, if you put it in the correct place. All the other changes I suggested (and made in my example) were not actually towards fixing the specific problem he mentioned, but they were things that could be improved upon nonetheless. The only thing I did in my example that actually fixes his current problem was adding in the spawn.

By adding in a spawn to put off the entirety of the loop's code block until later, they end up all being queued up to happen simultaneously the tick after the current function returns (unless the function sleeps elsewhere... speaking of which, that brings up something I wasn't thinking about when I made the suggestion which I must note in the next paragraph). The pieces then all end up being moved together one space at a time as he wants.

However, I will admit that I did overlook one detail that I just realised now. He would want to sleep between the two movement parts in his function so that it doesn't do both the north and south movement at the same time, making it appear still stationary. A simple sleep call after the first for(var/obj/O in world) loop finishes would solve this. Or spawn it off if you want to go with the robust route I mentioned before, which spawning has over sleep in similar cases to this one. However, this still does not mean that my version doesn't address his problem.
In response to Contact
It doesn't help your problem, but it does help. There are consequences for Bumping like this. Also, it is very important that you understand boolean variables.
In response to Loduwijk
ty for all ur help.
In response to Dever
Dever, I trust Loduwijk knows a plethora more than you do, and it will be a common thought once people even know you exist within this community.

You are right in a way, though. Nothing happens at the exact same time as another thing on a computer. It just happens so fast that you cannot tell if it is or not. (This has been previously stated, I just forgot by whom).

But you're wrong. It does help and it is what this guy is asking for. Perhaps you should read it over.
Page: 1 2