Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with a code pls
#1
ya i was trying out the paperdoll code on the old forums, and it kees giving me an "next without for" error heres the sub
Code:
Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long

For i = 1 To MAX_PLAYERS
If IsPlaying(i) = True Then
If GetPlayerMap(Index) = GetPlayerMap(i) Then
Armor = 0
Helmet = 0
Shield = 0
Weapon = 0
If GetPlayerArmorSlot(i) > 0 Then
Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
If GetPlayerHelmetSlot(i) > 0 Then
Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
If GetPlayerShieldSlot(i) > 0 Then
Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
If GetPlayerWeaponSlot(i) > 0 Then
Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
End If
End If
Next i
End Sub
its confusing me because i do have a for Confusedhock:
Reply
#2
sometimes that also means that you have an if without an end if or an end if without an if inside the for

tobody should even try to help you till you learn how to indent your code. It makes it much easier to find problems like this anyway.
Reply
#3
oh wait, thx misunderstood, that bit of advice, helped me i notice there were 4 end ifs missing in various places
Reply
#4
Code:
Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long

    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) = True Then
            If GetPlayerMap(Index) = GetPlayerMap(i) Then
                Armor = 0
                Helmet = 0
                Shield = 0
                Weapon = 0
                If GetPlayerArmorSlot(i) > 0 Then Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
                If GetPlayerHelmetSlot(i) > 0 Then Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
                If GetPlayerShieldSlot(i) > 0 Then Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
                If GetPlayerWeaponSlot(i) > 0 Then Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
                Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
                Call SendDataTo(Index, Packet)
            End If
        End If
    Next i
End Sub

The problem was that you had some "If" statements without "End If"s. You don't need the "End If" only if your code is on the same line, so I fixed it up.
Reply
#5
so if u do it the way u just posted u dont need the End Ifs?, thats cool, ill note that lol
Reply
#6
Hehe.. you kinda messed the whole thing up Tongue Here you got it:

Code:
Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long

For i = 1 To MAX_PLAYERS
If IsPlaying(i) = True Then
        If GetPlayerMap(Index) = GetPlayerMap(i) Then
            Armor = 0
            Helmet = 0
            Shield = 0
            Weapon = 0
        End If
    If GetPlayerArmorSlot(i) > 0 Then
        Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
    End If
    If GetPlayerHelmetSlot(i) > 0 Then
        Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
    End If
    If GetPlayerShieldSlot(i) > 0 Then
        Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
    End If
    If GetPlayerWeaponSlot(i) > 0 Then
        Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
    End If
Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
End If
Next i
End Sub

That should work!

Edit: Didn't see Pingu posted a fix.. =/
Reply
#7
William needs to learn to indent a bit better.

The only things that should be without indents is the sub declaration and the "Dim"s. After that, you start out with one indent and add another each time an "If", "For", "While", "With", or "Select" is used. you obviously remove one when you end each one.

I don't know if what you posted it your actual style or something quick you did, so ignore this post if you normally don't format like that.
Reply
#8
pingu Wrote:William needs to learn to indent a bit better.

The only things that should be without indents is the sub declaration and the "Dim"s. After that, you start out with one indent and add another each time an "If", "For", "While", "With", or "Select" is used. you obviously remove one when you end each one.

I don't know if what you posted it your actual style or something quick you did, so ignore this post if you normally don't format like that.
Hehe, it's nice that you try to teach me. But how I program isn't really anybodies business. And sure, I havnt taken classes in how to indent. But the way I code, is the way I want, the way I think it looks easiest Smile
Reply
#9
pingu everyone ahs their own coding standard, some diffrent some the same, i prefer to indent starting with the dims then everything else is 2 + whatever else (meaning ifs, for, whiles, ect.) and a space between EVERY line.
Reply
#10
I know everybody has their own style, but there are some styles that are easier to read than others.

William's is very difficult to read. All styles that have a bunch of code at the far left are always hard to see. The indenting of Dims doesn't really matter, though. Heck, I used to intent mine until I saw how it was done in Elysium and I started doing the same.

I don't see a readability issue with adding a line between code, but it's more of a scrolling thing. I'd rather not scroll down if I don't have to, so I try to compact it enough so it can still be read but less scrolling is needed (I have a laptop without a mouse, so I need to use that little furry thing to move the mouse).

It really doesn't matter, but it's another form of fasion. I like the person that wears the nicest clothes over someone who got a $2 shirt at K-Mart that is 3 sizes too big. It's not that important when you don't go outside (giving out the code), but it's important for people who need to impress with their coding skills.
Reply
#11
William Wrote:
pingu Wrote:William needs to learn to indent a bit better.

The only things that should be without indents is the sub declaration and the "Dim"s. After that, you start out with one indent and add another each time an "If", "For", "While", "With", or "Select" is used. you obviously remove one when you end each one.

I don't know if what you posted it your actual style or something quick you did, so ignore this post if you normally don't format like that.
Hehe, it's nice that you try to teach me. But how I program isn't really anybodies business. And sure, I havnt taken classes in how to indent. But the way I code, is the way I want, the way I think it looks easiest Smile

You haven't taken intenting classes? For shame!

Its simple. Each block of code is indented. Blocks of code go between for's if's while's and select cases, like pingu said.

You dont have a line of code right inline with the for loop if its inside the for loop, like you have
Code:
For i = 1 To MAX_PLAYERS
If IsPlaying(i) = True Then

and from there, you don't randomly and stupidly indent 2 tabs instead of 1 a la here:
Code:
For i = 1 To MAX_PLAYERS
If IsPlaying(i) = True Then
        If GetPlayerMap(Index) = GetPlayerMap(i) Then
            Armor = 0
            Helmet = 0
            Shield = 0
            Weapon = 0
        End If
    If GetPlayerArmorSlot(i) > 0 Then

This is good:
Code:
If GetPlayerArmorSlot(i) > 0 Then
        Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
    End If
    If GetPlayerHelmetSlot(i) > 0 Then
        Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
    End If
    If GetPlayerShieldSlot(i) > 0 Then
        Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
    End If
    If GetPlayerWeaponSlot(i) > 0 Then
        Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
    End If

Este es muy mal!
Code:
Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
End If
Next i
the packet part should be intented 1 tab to the right of the End If
the end if should be indented 1 tab to the right of the Next
and the next would be better indented one tab to the right of end sub.
Reply
#12
Just to point one thing out, I did think about the indents when I made the code. But didnt really wanna spend time on it.. So it was a ruff thing of what I wanted. This is actually how it would look if I made it my correct way:

Code:
Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long

For i = 1 To MAX_PLAYERS
    If IsPlaying(i) = True Then
        If GetPlayerMap(Index) = GetPlayerMap(i) Then
            Armor = 0
            Helmet = 0
            Shield = 0
            Weapon = 0
        End If
        If GetPlayerArmorSlot(i) > 0 Then
            Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
        End If
        If GetPlayerHelmetSlot(i) > 0 Then
            Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
        End If
        If GetPlayerShieldSlot(i) > 0 Then
            Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
        End If
        If GetPlayerWeaponSlot(i) > 0 Then
            Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
        End If
        Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
        Call SendDataTo(Index, Packet)
    End If
Next i
End Sub

Still it might differ from the Correct Lesson of it, but its my way.

If you want to cry, look at this (I made it long ago when i used rpgtoolkit):
http://www.key2heaven.net/bs.txt
Reply
#13
Quote:
Code:
Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long

For i = 1 To MAX_PLAYERS
    If IsPlaying(i) = True Then
        If GetPlayerMap(Index) = GetPlayerMap(i) Then
            Armor = 0
            Helmet = 0
            Shield = 0
            Weapon = 0
        End If
        If GetPlayerArmorSlot(i) > 0 Then
            Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
        End If
        If GetPlayerHelmetSlot(i) > 0 Then
            Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
        End If
        If GetPlayerShieldSlot(i) > 0 Then
            Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
        End If
        If GetPlayerWeaponSlot(i) > 0 Then
            Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
        End If
        Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
        Call SendDataTo(Index, Packet)
    End If
Next i
End Sub

That's much better, but there are two things to do and then it would be perfect (in my sense of style at least).

1. Indent that whole For loop one time. It's much easier to tell where a sub or function starts and ends if the start and end are the only lines that are on the far left side. The next doesn't effect that too much in this example, but any other code not in one of those statements would ruin the effect more.

2. "If IsPlaying(i) Then" looks so much nicer than adding a "= true" and they do the same thing. It's always best to make it logical, so that you can read it out like a sentence. "If this guy is playing then" makes more sense than "If this guy is playing and that is true, then". It's better for variables like "InEditor", because it makes so much more sense. "Do While NotDone" is my favorite...
Reply
#14
pingu Wrote:1. Indent that whole For loop one time. It's much easier to tell where a sub or function starts and ends if the start and end are the only lines that are on the far left side. The next doesn't effect that too much in this example, but any other code not in one of those statements would ruin the effect more.

2. "If IsPlaying(i) Then" looks so much nicer than adding a "= true" and they do the same thing. It's always best to make it logical, so that you can read it out like a sentence. "If this guy is playing then" makes more sense than "If this guy is playing and that is true, then". It's better for variables like "InEditor", because it makes so much more sense. "Do While NotDone" is my favorite...
You do have some good points, some Wink
Reply
#15
Ohh and another thing to bully/pester you about!

I know in this case you might not have known that the packet line would wrap to the next line, but when in the vb ide you have something wrap to the next line, make the 2nd line indented atleast 1 from the first like

sooo:
Code:
Packet="blah" & sep_char & "stupid" &
    sep_char & end_char
Reply
#16
nvm got it working
Reply
#17
Misunderstood Wrote:Ohh and another thing to bully/pester you about!

I know in this case you might not have known that the packet line would wrap to the next line, but when in the vb ide you have something wrap to the next line, make the 2nd line indented atleast 1 from the first like

sooo:
Code:
Packet="blah" & sep_char & "stupid" &
    sep_char & end_char

I've never tried it, but don't you need a "_" at the end of a line to signal that it continues on the next line?
Reply
#18
Yes you do, without the quotes ("") Wink
Reply
#19
yaaa i have no idea why, but it just randomly stopped workign, and it wasnt working "right" before, by any chance can any1 get me a copy of mirage with paperdoll already implemented?, or maybe a gueranteed tutorial?
Reply
#20
oh yea, you need a _ to tell vb you are going to the next line. I forgot this was crappy vb. In most languages you don't need to do that Tongue
Reply
#21
kk got this workign xD, but uhh, it doesnt work until you liek walk into another map, any1 kno a fix?
Reply
#22
Because its called: SendIndexWornEquipmentFromMap

And it probably is called upon map switch.
Reply
#23
pingu Wrote:I've never tried it, but don't you need a "_" at the end of a line to signal that it continues on the next line?

Actually dude.. You do need an underscore.. In visual basics it means the line of code has been divided onto another line..
Reply
#24
Dark Echo Wrote:
pingu Wrote:I've never tried it, but don't you need a "_" at the end of a line to signal that it continues on the next line?

Actually dude.. You do need an underscore.. In visual basics it means the line of code has been divided onto another line..

ftw? Are you dyslexic (sp?) Echo? Tongue
Reply
#25
kk fixed it lol, i just had it call that sub everytime you used an item lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)