ID:147387
 
//////////CODE STARTS HERE////////////
mob
verb
Join_Game(M as mob in world)
set name = "Join Game"
if(second_player == "taken")
usr << "All spots are taken"
return 0
if(first_player == "taken")
src.verbs-=/mob/verb/Join_Game
rank = "2nd Player"
second_player = "taken"
world << "[M] is 2nd Player!"
if(first_player == "free")
src.verbs-=/mob/verb/Join_Game
rank = "1st Player"
world << "[M] is 1st Player!"
first_player = "taken"

proc
join_game_proc()
if(second_player == "taken"|first_player == "taken") if :warning: if statement has no effect


What's the deal here? Why does the if statement have no effect? Could someone break this problem down for me?
I believe that you need to add a | like this:
if(second_player == "taken"||first_player == "taken")
not this:
if(second_player == "taken"|first_player == "taken")
Because you aren't doing anything based on that if statement. This could be because you actually don't have anything under the if, or, more commonly, you may not have properly indented the code beneath it.

verb/Test1()
if(something) // Error from no code.

verb/Test2()
if(something) // Error from improperly indented code.
src.name = "Mud"

verb/Test3()
if(something) // This works. Indented code block beneath if executed if 'something' is true.
src.name = "Succesfull"


*EDIT*

Yeah, that too :P || rather than |, unless you were actually trying to use the binary 'or' of those.
In response to Tabu34
Tabu34 wrote:
I believe that you need to add a | like this:
if(second_player == "taken"||first_player == "taken")
not this:
if(second_player == "taken"|first_player == "taken")

If I put && instead. What effect would that have? I am looking for the "or" effect inbetween first and second player. So if 1st player isnt open, second player will.
In response to ZLegend
actually i dont think it will work. It is like saying
if the first player is taken or the second player is taken then do whatever is afterwards
In response to Tabu34
im trying to say: If 1st and second player are taken, you cant select this verb
In response to ZLegend
ZLegend wrote:
im trying to say: If 1st and second player are taken, you cant select this verb

then you want the 'and' operator, which is && i believe.

so you might want something along the lines of this pseudo-code:
if((player1=='taken') && (player2=='taken')) {
// put code here that leaves the proc immediately or jumps out
} else {
// continue with normal proc code here
}

OR, the following style might be better suited (and easier to read) (again this is pseudo-code- you will need to change it to fit the DM style of programming):
if((player1 is not 'taken') && (player2 is not 'taken')) {
// normal proc code here
} else {
// put code here that leaves the proc immediately
}


check how if statements can be layered with multiple conditions. the above example is from PHP, but should be close (BYOND might accept the
if(player1=='taken' && player2=='taken')
style and give you the same behavior).
mob
verb
Join_Game(M as mob in world)
set name = "Join Game"
check_players()
join_game_proc()
if(first_player == "taken")
src.rank = "2nd Player"
second_player = "taken"
world << "[M] is 2nd Player!"
if(first_player == "free")
rank = "1st Player"
world << "[M] is 1st Player!"
first_player = "taken"


Can someone just break down why this verb changes my rank from 1st player to second player when I select an npc to be the 2nd player?

---------------------------------------------------------

mob
monsters
Blob
icon = 'icons.dmi'
icon_state = "blob"
Click()
usr.Take_control()

mob
var/disable_mob_movement=0
proc/disable_mob_movement()
disable_mob_movement=1
client
Move()
if(mob.disable_mob_movement)return 0
.=..()

mob/proc/Place_a_mob()
src.loc=locate(x,y,z) // .src may cause problems. Fix if needed.

mob/proc/Take_control()
disable_mob_movement()
Place_a_mob()
Move(get_step(src,NORTH))
Move(get_step(src,SOUTH))
Move(get_step(src,WEST))
Move(get_step(src,EAST))


I can't seem to figure out why I click another mob, it disables my movement and I can't move that mob.
In response to Zlegend2
Zlegend2 wrote:
mob
verb
Join_Game(M as mob in world)
set name = "Join Game"
check_players()
join_game_proc()
if(first_player == "taken")
src.rank = "2nd Player"
second_player = "taken"
world << "[M] is 2nd Player!"
if(first_player == "free")
rank = "1st Player"
world << "[M] is 1st Player!"
first_player = "taken"


Can someone just break down why this verb changes my rank from 1st player to second player when I select an npc to be the 2nd player?

Because you are telling it to. When you use this verb, you are the src. So, when first_player is already set to "taken", setting src.rank to '2nd Player' sets your rank. If you want it to set the rank of the mob you selected, use M.rank rather than src.rank.
In response to Flick
Flick wrote:
Zlegend2 wrote:
mob
verb
Join_Game(M as mob in world)
set name = "Join Game"
check_players()
join_game_proc()
if(first_player == "taken")
src.rank = "2nd Player"
second_player = "taken"
world << "[M] is 2nd Player!"
if(first_player == "free")
rank = "1st Player"
world << "[M] is 1st Player!"
first_player = "taken"


Can someone just break down why this verb changes my rank from 1st player to second player when I select an npc to be the 2nd player?

Because you are telling it to. When you use this verb, you are the src. So, when first_player is already set to "taken", setting src.rank to '2nd Player' sets your rank. If you want it to set the rank of the mob you selected, use M.rank rather than src.rank.

Use var/mob/M ?
In response to Zlegend2
You already set M to be a mob in the world
In response to N1ghtW1ng
Zlegend, please do not start another thread on the same topic in the same section (you created a new one on the same code less than an hour after i replied to the original)- this is called 'double-posting'. there was nothing wrong with continuing the discussion in the original thread. i have re-attached your second thread to the original.

moe on-topic: have you even tried the && idea presented earlier? done properly, that should solve your problems just fine.