Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

I need help scripting (didnt know where to put this)


Nobody
 Share

Recommended Posts

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 1
If GetPlayerAccess(Index) = 0 Then
Call GlobalMsg(GetPlayerName(Index) & " has joined " & GameName & "!", GREY)
                  Case 2 
                  If GetPlayerAccess(Index) = 1 Then
Call GlobalMsg("Mod " & GetPlayerName(Index) & " has joined " & GameName & "!", PINK)
                  Case 3
                  If GetPlayerAccess(Index) = 2 Then
Call GlobalMsg("Mapper " & GetPlayerName(Index) & " has joined " & GameName & "!", BLUE)
                Case 4
                  If GetPlayerAccess(Index) = 3 Then
Call GlobalMsg(" Developer" & GetPlayerName(Index) & " has joined " & GameName & "!", RED)
                  Case 5
                  If GetPlayerAccess(Index) = 4 Then
Call GlobalMsg("Admin " & GetPlayerName(Index) & " has joined " & GameName & "!",CYAN)
                Case 6
                  If GetPlayerAccess(Index) = 5 Then
Call GlobalMsg("Owner " & GetPlayerName(Index) & " has joined " & GameName & "!", MAGENTA)

End If

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
Link to comment
Share on other sites

```
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

End If

Select 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

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
'Blah
ElseIf value = 2 Then
'Blah
ElseIf value = 3 Then
'Blah
ElseIf value = 4 Then
'Blah
End 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
        'Blah
End 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...