Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 i made a script and it doesn't work i am new at scripting and i already read all of yellow moles scripting tutorial and i wanted to try this (: any ideas on how i could improve so that it works?' Executes when a player logs into the game.Sub JoinGame(Index) Case 1If GetPlayerAccess(Index) = 0 ThenCall GlobalMsg(GetPlayerName(Index) & " has joined " & GameName & "!", GREY) Case 2 If GetPlayerAccess(Index) = 1 ThenCall GlobalMsg("Mod " & GetPlayerName(Index) & " has joined " & GameName & "!", PINK) Case 3 If GetPlayerAccess(Index) = 2 ThenCall GlobalMsg("Mapper " & GetPlayerName(Index) & " has joined " & GameName & "!", BLUE) Case 4 If GetPlayerAccess(Index) = 3 ThenCall GlobalMsg(" Developer" & GetPlayerName(Index) & " has joined " & GameName & "!", RED) Case 5 If GetPlayerAccess(Index) = 4 ThenCall GlobalMsg("Admin " & GetPlayerName(Index) & " has joined " & GameName & "!",CYAN) Case 6 If GetPlayerAccess(Index) = 5 ThenCall GlobalMsg("Owner " & GetPlayerName(Index) & " has joined " & GameName & "!", MAGENTA)End IfCall PlayerMsg(Index, "Welcome to " & GameName & "!", WHITE)If LenB(MOTD) <> 0 ThenCall PlayerMsg(Index, "MOTD: " & MOTD, BRIGHTCYAN)End IfCall SendWhosOnline(Index)End Sub Link to comment Share on other sites More sharing options...
Ruins of Hell Posted December 5, 2009 Share Posted December 5, 2009 ```Sub JoinGame(Index)Select Case GetPlayerAccess(index) If GetPlayerAccess(Index) = 0 Then Call GlobalMsg(GetPlayerName(Index) & " has joined " & GameName & "!", GREY) Case 1 Call GlobalMsg("Mod " & GetPlayerName(Index) & " has joined " & GameName & "!", PINK) Case 2 Call GlobalMsg("Mapper " & GetPlayerName(Index) & " has joined " & GameName & "!", BLUE) Case 3 Call GlobalMsg(" Developer" & GetPlayerName(Index) & " has joined " & GameName & "!", RED) Case 4 Call GlobalMsg("Admin " & GetPlayerName(Index) & " has joined " & GameName & "!",CYAN) Case 5 Call GlobalMsg("Owner " & GetPlayerName(Index) & " has joined " & GameName & "!", MAGENTA)End Select Call PlayerMsg(Index, "Welcome to " & GameName & "!", WHITE) If LenB(MOTD) <> 0 Then Call PlayerMsg(Index, "MOTD: " & MOTD, BRIGHTCYAN) End If Call SendWhosOnline(Index)End Sub```You had several unclosed Ifs, and then you were using cases for an if? Link to comment Share on other sites More sharing options...
Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 oh i am new at this could you break it down a little XDlike i should not be using cases their ?how would i close the ifs? Link to comment Share on other sites More sharing options...
Ruins of Hell Posted December 5, 2009 Share Posted December 5, 2009 End IfSelect Case picks the case that matches what you select.If you wanted to have multiple options with an If, you would use:```If GetPlayerAccess(index) = 0 Then...code...ElseIf GetPlayerAccess(index) = 1 Then...code...ElseIf GetPlayerAccess(index) = 2 Then...code...ElseIf GetPlayerAccess(index) = 3 Then...code...ElseIf GetPlayerAccess(index) = 4 Then...code...ElseIf GetPlayerAccess(index) = 5 Then...code...End If``` Link to comment Share on other sites More sharing options...
Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 Thank you :cheesy: this will help me a lot XDby the way how do you put the code inCode: (vb)for future references Link to comment Share on other sites More sharing options...
Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 And it works :azn: :cry: :azn: Link to comment Share on other sites More sharing options...
Ruins of Hell Posted December 5, 2009 Share Posted December 5, 2009 ['code]…code...[/'code]Remove the '.Warning - while you were typing a new reply has been posted. You may wish to review your post.@Nobody:> And it works :azn: :cry: :azn:Of course it works! Link to comment Share on other sites More sharing options...
Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 Thanks a lot man :cheesy: Link to comment Share on other sites More sharing options...
Ruins of Hell Posted December 5, 2009 Share Posted December 5, 2009 No problem, it's nice to see new scripters around :D. Link to comment Share on other sites More sharing options...
Lam3r Posted December 5, 2009 Share Posted December 5, 2009 Hey real quick if you could answer this Soul (sorry i didn't want to start a new thread just for this)What exactly is a Case used for? Why not just use If/Else If? Or a While loop or something? Link to comment Share on other sites More sharing options...
Nobody Posted December 5, 2009 Author Share Posted December 5, 2009 The final Edit of this script can be found on http://www.touchofdeathforums.com/smf/index.php/topic,54981.msg582041/topicseen.html#new (: enjoy Link to comment Share on other sites More sharing options...
Ruins of Hell Posted December 5, 2009 Share Posted December 5, 2009 @Lam3r:> Hey real quick if you could answer this Soul (sorry i didn't want to start a new thread just for this)> > What exactly is a Case used for? Why not just use If/Else If? Or a While loop or something?Because, using Cases is **a lot** faster than going through all those conditional checks. Link to comment Share on other sites More sharing options...
balliztik1 Posted December 5, 2009 Share Posted December 5, 2009 Well, it depends on the situation, really. Cases are actually slower, but they are more precise. That is, they don't have to check every condition, but they are slower at finding the right condition. For this reason, it's not a good idea to use a Case for anything less than 3 or 4 choices, as it will probably not be necessary. However, because Cases are order independent, no matter what value you throw at them, there won't be a delay. For instance:```If value = 1 Then'BlahElseIf value = 2 Then'BlahElseIf value = 3 Then'BlahElseIf value = 4 Then'BlahEnd If```Say the value you use is 4\. This means it has to test the first condition, fail it, then the second, and then the third before finally finding the correct choice. On the other hand:```Select Case value Case 1 'Blah Case 2 'Blah Case 3 'Blah Case 4 'BlahEnd Select```This code will jump straight to 4\. Because it's not testing a conditional, but rather "jumping" to the correct value, it skips unnecessary checks. However, suppose the value was 1\. Instead of immediately fulfilling the condition, it must find the variable's value, then make the aforementioned jump. In short, the longer the string of ElseIfs, the less efficient they become, and the shorter a Case switch is, the less efficient it becomes.Yeah, a bit of random info for the topic, but hey, I've got time. Knowledge is power! ;D Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now