Mirage Source http://miragesource.net/forums/ |
|
help with a code pls http://miragesource.net/forums/viewtopic.php?f=201&t=541 |
Page 1 of 11 |
Author: | Clu [ Sat Sep 23, 2006 1:17 pm ] |
Post subject: | help with a code pls |
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 |
Author: | Misunderstood [ Sat Sep 23, 2006 1:31 pm ] |
Post subject: | |
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. |
Author: | Clu [ Sat Sep 23, 2006 1:43 pm ] |
Post subject: | |
oh wait, thx misunderstood, that bit of advice, helped me i notice there were 4 end ifs missing in various places |
Author: | pingu [ Sat Sep 23, 2006 1:44 pm ] |
Post subject: | |
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. |
Author: | Clu [ Sat Sep 23, 2006 1:47 pm ] |
Post subject: | |
so if u do it the way u just posted u dont need the End Ifs?, thats cool, ill note that lol |
Author: | William [ Sat Sep 23, 2006 2:03 pm ] |
Post subject: | |
Hehe.. you kinda messed the whole thing up 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.. =/ |
Author: | pingu [ Sat Sep 23, 2006 2:31 pm ] |
Post subject: | |
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. |
Author: | William [ Sat Sep 23, 2006 2:51 pm ] |
Post subject: | |
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 |
Author: | grimsk8ter11 [ Sat Sep 23, 2006 2:54 pm ] |
Post subject: | |
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. |
Author: | pingu [ Sat Sep 23, 2006 4:00 pm ] |
Post subject: | |
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. |
Author: | Misunderstood [ Sat Sep 23, 2006 4:42 pm ] |
Post subject: | |
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. |
Author: | William [ Sat Sep 23, 2006 4:58 pm ] |
Post subject: | |
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 |
Author: | pingu [ Sat Sep 23, 2006 5:05 pm ] |
Post subject: | |
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... |
Author: | William [ Sat Sep 23, 2006 5:13 pm ] |
Post subject: | |
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 |
Author: | Misunderstood [ Sat Sep 23, 2006 6:07 pm ] |
Post subject: | |
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 |
Author: | Clu [ Sat Sep 23, 2006 6:31 pm ] |
Post subject: | |
nvm got it working |
Author: | pingu [ Sat Sep 23, 2006 7:09 pm ] |
Post subject: | |
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? |
Author: | William [ Sat Sep 23, 2006 8:08 pm ] |
Post subject: | |
Yes you do, without the quotes ("") |
Author: | Clu [ Sat Sep 23, 2006 9:36 pm ] |
Post subject: | |
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? |
Author: | Misunderstood [ Sun Sep 24, 2006 12:42 am ] |
Post subject: | |
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 |
Author: | Clu [ Sun Sep 24, 2006 9:19 pm ] |
Post subject: | |
kk got this workign xD, but uhh, it doesnt work until you liek walk into another map, any1 kno a fix? |
Author: | William [ Sun Sep 24, 2006 9:56 pm ] |
Post subject: | |
Because its called: SendIndexWornEquipmentFromMap And it probably is called upon map switch. |
Author: | Dark Echo [ Mon Sep 25, 2006 3:07 am ] |
Post subject: | |
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.. |
Author: | Rian [ Mon Sep 25, 2006 3:14 am ] |
Post subject: | |
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? |
Author: | Clu [ Mon Sep 25, 2006 11:51 am ] |
Post subject: | |
kk fixed it lol, i just had it call that sub everytime you used an item lol |
Page 1 of 11 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |