Mirage Source

Free ORPG making software.
It is currently Sat Apr 27, 2024 7:28 pm

All times are UTC




Post new topic Reply to topic  [ 272 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next
Author Message
 Post subject: help with a code pls
PostPosted: Sat Sep 23, 2006 1:17 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
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 :shock:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 1:31 pm 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 1:43 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
oh wait, thx misunderstood, that bit of advice, helped me i notice there were 4 end ifs missing in various places


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 1:44 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 1:47 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
so if u do it the way u just posted u dont need the End Ifs?, thats cool, ill note that lol


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 2:03 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Hehe.. you kinda messed the whole thing up :P 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.. =/

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 2:31 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 2:51 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
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 :)

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 2:54 pm 
Offline
Pro

Joined: Mon May 29, 2006 2:58 pm
Posts: 370
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 4:00 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 4:42 pm 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
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 :)


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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 4:58 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
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

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 5:05 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
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...

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 5:13 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
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 ;)

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 6:07 pm 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 6:31 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
nvm got it working


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 7:09 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
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?

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 8:08 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Yes you do, without the quotes ("") ;)

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 9:36 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
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?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 12:42 am 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
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 :P


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 9:19 pm 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
kk got this workign xD, but uhh, it doesnt work until you liek walk into another map, any1 kno a fix?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 9:56 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Because its called: SendIndexWornEquipmentFromMap

And it probably is called upon map switch.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:07 am 
Offline
Knowledgeable

Joined: Tue May 30, 2006 5:11 am
Posts: 156
Location: Australia
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..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:14 am 
Offline
Persistant Poster
User avatar

Joined: Tue May 30, 2006 2:07 am
Posts: 836
Location: Nashville, Tennessee, USA
Google Talk: rs.ruggles@gmail.com
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? :P

_________________
I'm on Facebook! Google Plus My Youtube Channel My Steam Profile

Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 11:51 am 
Offline
Regular

Joined: Fri Jul 28, 2006 9:20 pm
Posts: 39
Location: <--soemwhere in that general direction
kk fixed it lol, i just had it call that sub everytime you used an item lol


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 272 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group