SIMPLE QUESTION: then expected

Snip of code.

Starts at line #32
[lua]
if TEAM = ( “TEAM_SOLDIER” ) then
pl:Give( “knife” )
pl:Give( “weapon_glock” )
end
[/lua]

Error:



/gamemode/init.lua:32: 'then' expected near '='


Lua syntax goes as follows:
a = 1; // set a equal to 1
if a == 1 then… // checks if a is equal to 1
if you add another equals sign to your code you would be on the right track.

However there are more errors in your code:
Your calling TEAM on no object so that will just break right there.
Also when you return team it returns a number value for the team, your trying to compare it to the team name, if you wanted to compare a players team to a name you would have to use something like :
[lua]
if team.GetName( ply:Team() ) == “TEAM_SOLDIER” then…
[/lua]

if i understand what you want correctly; this is how i would go about doing it.
[lua]
function GM:PlayerSpawn( ply ) // function called whenever a player spawns
if ply:Team() == 1 then //If the player object is on team 1 then
ply:Give( “knife” )// give him a knife
ply:Give( “weapon_glock” )// and a glock
ply:PrintMessage( HUD_PRINTTALK, "Good luck with your coding " … ply:Name())// prints a message in the players chat box
end
end
[/lua]
hope this helps ya

[lua]
function GM:PlayerLoadout( pl )
TEAM = ( “TEAM_SOLDIER” )
end
[/lua]

I had that in my code originally.

[editline]03:28AM[/editline]



/gamemode/init.lua:16: unexpected symbol near '=='


Starts at line 15
[lua]
function GM:PlayerConnect( ply )
ply:Team() == 1;
end
[/lua]

Yea, look what meka/sniper said,

Use of == :
[lua]if( something == something )then[/lua]

Use of = :
[lua]something = 3[/lua]

If team == instead of = .

Why did three people have to post with the same answer?

It’s facepunch what do you expect?

If they the IQ to register, they sure as hell should get the gist of the answer in one post.

Troll much?

agreed he trolls everywhere

Oh the irony.

Again.



/gamemode/init.lua:16: unexpected symbol near '=='


Starts at line 15
[lua]
function GM:PlayerConnect( ply )
ply:Team() == 1;
end
[/lua]

[lua]
function GM:PlayerConnect( ply )
ply:Team() = 1;
end
[/lua]

:hurr:

If you notice Cubar the error consists of 2 ‘=’ signs. So that will not fix it :slight_smile:

ply:SetTeam( 1 )

It doesnt expect the “;” after two “=”

How do I respond to that team? Eg. if ply:Team() == 1 then or…



if ply:Team( ) == 1 then
  ply:Give( "weapon_crowbar" )
end


Oh yeah i didn’t read properly rofl.

Not at all. It doesn’t expect the second ‘=’.