ID:266705
 
How would I make it where everyone that has the battle var at one, gets teleported to a spot.This is what I have before it but I can't think of what to add.

            Start_Round()
set category="Host"
if (roundstarted==1)
usr<<"<b>Round already started."
else
switch(input("What level do you want it to be at","Level","Space,Volcano, or City")in list("Space","Volcano","City"))
if ("Space")
world<<"<font color=silver><b>Round starting in 10"
sleep(10)
world<<"<font color=silver><b>Round starting in 9"
sleep(10)
world<<"<font color=silver><b>Round starting in 8"
sleep(10)
world<<"<font color=silver><b>Round starting in 7"
sleep(10)
world<<"<font color=silver><b>Round starting in 6"
sleep(10)
world<<"<font color=silver><b>Round starting in 5"
sleep(10)
world<<"<font color=silver><b>Round starting in 4"
sleep(10)
world<<"<font color=silver><b>Round starting in 3"
sleep(10)
world<<"<font color=silver><b>Round starting in 2"
sleep(10)
world<<"<font color=silver><b>Round starting in 1"
sleep(10)
world<<"<font color=silver><b>Round starting in 0"


If you can show me a way to do this it would help greatly thanks.

-Beld
Emperor Beld wrote:
How would I make it where everyone that has the battle var at one, gets teleported to a spot.This is what I have before it but I can't think of what to add.

Well, you'd have to loop through everyone in the world with a for() loop and then check to see if their battle var is equal to 1. For example,
for(var/mob/M in world)     //Loops through all mobs in world
   if(M.battle == 1)        //Checks the battle var
      M.loc = locate(1,1,2) //Relocates those with a 1 battle var


In response to Creek
Also, your battle announcement is inefficient. Instead of that long chain, have a loop that looks something like this...
var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver><b>Round starting in [Time]"
sleep(10)
Time -= 1
goto Countdown // Takes you back to Countdown
In response to Garthor
I have another question how would I make where you teleport to one of a bunch of differnt locations that I pick.I can't use random because its a side-scrolling game and if you dont start out abouve something dense you'll fal to the bottom and lose a life
In response to Garthor
An even better way would be to do:
var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver>Round starting in [Time]"
spawn(1)
Time -= 1
goto Countdown // Takes you back to Countdown


Spawn allows BYOND to do other things while it's waiting for something to happen. A second may not be a lot to you, but a 1GHz processor executes a billion proceses every second. That's a lot of wasted power :-)
In response to Emperor Beld
Why can't you use random?

Anyway, if you've specified the locations, you should use pick() Look it up.
In response to ShadowWolf
ShadowWolf wrote:
An even better way would be to do:
var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver>Round starting in [Time]"
spawn(1)
Time -= 1
goto Countdown // Takes you back to Countdown


Spawn allows BYOND to do other things while it's waiting for something to happen. A second may not be a lot to you, but a 1GHz processor executes a billion proceses every second. That's a lot of wasted power :-)</font>

Close your tags. Also, an even better even better way to do this would be:
> var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver><b>Round starting in [Time]</font></b>"
spawn(10)
Time -= 1
goto Countdown // Takes you back to Countdown
In response to Garthor
var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver>Round starting in [Time]</font>"
spawn(10)
Time -= 1
goto Countdown // Takes you back to Countdown</DM>

var/global/Time = 10
While(Time)
world << "<font color=silver>Round starting in [Time]</font>"
sleep(10)
Time --

get rid of that goto, goto's are bad coding.
In response to WildBlood
WildBlood wrote:
var/global/Time
Countdown // Marks this place for returning to later
if(Time)
world << "<font color=silver>Round starting in [Time]</font>"
spawn(10)
Time -= 1
goto Countdown // Takes you back to Countdown</DM>

var/global/Time
When(!Time)
world << "<font color=silver>Round starting in [Time]</font>"
spawn(10)
Time --

get rid of that goto, goto's are bad coding.

All three of you have just produced lousy code, one after the other.
Not one of you noticed that the lines under spawn() have to be indented in order to be spawned off.

"When" is not a valid loop construct--and if it was, your code still wouldn't be right because you're thinking of "until"; which exists in Perl, but not DM.

For the purposes of this proc, sleep() is a much better choice than spawn(). If anything else is waiting that needs to be done right away, spawning off the entire proc is the way to go.

Lummox JR
In response to Lummox JR
Oh boy i made a mistake use while instead of when which will work. Woooo little mistake there and were called lousy coders. Really dont try bringing people down when they send in suggestions when trying to help others
[See suggestion above, again]
In response to WildBlood
WildBlood wrote:
Oh boy i made a mistake use while instead of when which will work. Woooo little mistake there and were called lousy coders. Really dont try bringing people down when they send in suggestions when trying to help others
[See suggestion above, again]

Your suggestion still won't work, because while(!time) will skip the loop if time is nonzero; if it is zero, then the loop will only execute once. The correct statement is while(time).

I didn't say you were lousy coders, but that you all posted lousy code. All three of you made a pretty basic mistake, coupled with another that was unique to each of you.
Anyway, how does it help others to see broken code offered as a potential solution to their problem? That usually does more harm than good.

Lummox JR
In response to Lummox JR
MY first code was good.
In response to Garthor
Garthor wrote:
MY first code was good.

No, it wasn't, because Time was null. You didn't set a number to it, so it would just be minusing from null. Here's what yours would come out as...


<font color=silver>
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
Round starting in
</font>

...to infinity, eventually leading to a crash


If it didn't do that, it would just spit out an error.

=V
In response to Vortezz
I didn't specify so that he didn't copy and paste it into his code.
In response to Lummox JR
I already had it fixed, you mighta been reading my post while i was editing it
In response to Garthor
Garthor wrote:
MY first code was good.

When I said "all three", that's what I meant. Aside from the infinite loop problem Vortezz pointed out, your code used an awful goto where it should have used while(). I'm a big fan of goto and think all good languages should have it for the most complex situations, but 99% of loops can and should be done without it. So even if it worked, it's still lousy code by Bad Design.

The dirt-simplest approach actually wouldn't even use a while loop, but a for loop.
for(var/time=10,time>0,--time)
world << "Round starting in [time] second\s."
sleep(10)

That is of course if you can stand spammy countdown messages like that to begin with.

Lummox JR
In response to WildBlood
WildBlood wrote:
I already had it fixed, you mighta been reading my post while i was editing it

I was just responding to the substance of your new message, which said it should have been while() instead of When(). Since the original statement was When(!time), I was addressing the fact that based on what you said, that would make it while(!time) which would still be wrong.

Lummox JR
In response to Garthor
Garthor wrote:
Why can't you use random?

Anyway, if you've specified the locations, you should use pick() Look it up.

I have to use random because its a side scrolling game and if they start out not above the dense tile they fall to the bottom and lose life.Also I tried the pick proc but I cant seem to get it to work right.This is what I have for it
                            for(var/mob/M in world)     //Loops through all mobs in world
if(M.battle == 1) //Checks the battle var
M.pick(
M.loc=locate(5,5,1),
prob(15)
M.loc=locate(7,5,1),
prob(15)
M.loc=locate(10,2,1),
prob(15)
M.loc=locate(20,2,1)
)
else
usr<<"<font color=white><b>If you want to join the battle click the join battle verb."


I get 8 errors that say.

Host verbs.dm:43:error: M: missing comma ',' or right-paren ')'
Host verbs.dm:43:error: M: expected end of statement
Host verbs.dm:43:error: ,: expected }
Host verbs.dm:40:error: location of top-most unmatched {
Host verbs.dm:43:error: ,: expected }
Host verbs.dm:39:error: location of top-most unmatched {
Host verbs.dm:43:error: ,: expected }
Host verbs.dm:30:error: location of top-most unmatched {

I can't figuire out whats wrong so if you know please help.

-Beld
In response to Emperor Beld
M.loc = pick( ... and so on. Take out the m.loc on the pick things.