Author Topic: script "merging"  (Read 25980 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
script "merging"
« Reply #15 on: 2005-05-15, 08:33:29 PM »
The if statement that you put at the beginning has to be inside of a sub, otherwise it will never execute (and will cause an error), and it also requires an end if statement.  Also, I'm not sure, but that if statement just doesn't look correct to me.  What's the part after the apostrophe for?  Is that all on one line in the script, rather than three lines, as it shows up here?  You can get rid of it to make it easier to understand the script if it is, because it's just a comment anyway.
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #16 on: 2005-05-15, 10:13:41 PM »
Yea, I put that there as a note to myself, but is that line in the right place?

Ok.., I've tried several combinations with the If statement but I honestly just don't know what I'm doing. I tried putting Sub infront of the If ProjectObj...  and putting an End Sub after it but that didn't work, I tried putting the If statement in with the Sub Player_On... but that didn't work either... I'm really sorry if I'm being a pain in the *** but I don't know vbs or any scripting language for that matter (I can just barely squeak by in html).
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
script "merging"
« Reply #17 on: 2005-05-16, 06:52:36 AM »
http://gamedev.comdel.net/viewtopic.php?t=8
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp

Code: [Select]
' ======== INITIAL STARTUP SCRIPT (Number 0) =========

Sub Player_OnPlayInit()
   HostObj.StartScript=1
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16



Option Explicit

Dim XOff, YOff

Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo

Const nSprWidth = 48
Const nSprHeight = 89

Sub Display_KeyDown(KeyCode, Shift)
    If KeyCode = 69 Then P2Actions = P2Actions Or ACTION_UP
    If KeyCode = 83 Then P2Actions = P2Actions Or ACTION_LEFT
    If KeyCode = 68 Then P2Actions = P2Actions Or ACTION_DOWN
    If KeyCode = 70 Then P2Actions = P2Actions Or ACTION_RIGHT
End Sub

Sub Display_KeyUp(KeyCode, Shift)
    If KeyCode = 69 Then P2Actions = P2Actions And Not ACTION_UP
    If KeyCode = 83 Then P2Actions = P2Actions And Not ACTION_LEFT
    If KeyCode = 68 Then P2Actions = P2Actions And Not ACTION_DOWN
    If KeyCode = 70 Then P2Actions = P2Actions And Not ACTION_RIGHT
End Sub

Sub Player_OnAfterMoveSprites()
    Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
    Set oPlayer = ProjectObj.GamePlayer
    Set oMap = oPlayer.rMap
    Set oLayer = oMap.MapLayer(0)

    If intSprTwo < 0
        For i = 0 to oLayer.SpriteCount - 1
            If oLayer.Sprite(i).rDef.Name = "Player2" then intSprTwo = i
        next
    End If

'Two Player Stuff
    If ProjectObj.GamePlayer.rMap.name = "0-4LevelSelect" then
        With oLayer.Sprite(intSprTwo)
            .ProcessAction(P2Actions)
            oMap.ViewTop = 240

            If P2OffsetX + oPlayer.ScrollMarginX > .X Then
                P2OffsetX = .X - oPlayer.ScrollMarginX
            End If

            If P2OffsetX + oMap.ViewWidth - oPlayer.ScrollMarginX < .X + nSprWidth Then
                P2OffsetX = .X - oMap.ViewWidth + oPlayer.ScrollMarginX + nSprWidth
            End If

            If P2OffsetY + oPlayer.ScrollMarginY > .Y Then
                P2OffsetY = .Y - oPlayer.ScrollMarginY
            End If

            If P2OffsetY + oMap.ViewHeight - oPlayer.ScrollMarginY < .Y + nSprHeight Then
                P2OffsetY = .Y - oMap.ViewHeight + oPlayer.ScrollMarginY + nSprHeight
            End If

            If P2OffsetX < 0 Then P2OffsetX = 0
            If P2OffsetY < 0 Then P2OffsetY = 0
            nLyrWid = oLayer.Columns * nSprWidth
            nLyrHgt = oLayer.Rows * nSprHeight
            If P2OffsetX > nLyrWid - oMap.ViewWidth Then P2OffsetX = nLyrWid - oMap.ViewWidth
            If P2OffsetY > nLyrHgt - oMap.ViewHeight Then P2OffsetY = nLyrHgt - oMap.ViewHeight
            oMap.Draw P2OffsetX, P2OffsetY, False
            oMap.ViewTop = 0
        End With
    End If

'Automatic Scrolling Stuff
    If ProjectObj.GamePlayer.rMap.name = "2-4BonusLevel" then
        XOff = XOff + 1
        With ProjectObj.GamePlayer
            if .PlayerSprite.X <= XOff then
                if .PlayerSprite.DX < 0 then .PlayerSprite.DX = 1
                .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
                if .PlayerSprite.X < XOff - .PlayerSprite.Width / 2 then
                    XOff = 1
                End if
            end if
            .rMap.Draw XOff, YOff
        End With
    End If

End Sub

Sub Player_OnControllerMove(OldActions, NewActions)

'Jumping Player
    With ProjectObj.GamePlayer.PlayerSprite
        If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
            If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
                .DY = - .rDef.Template.JumpHeight
            End If
        End If
    End With

End Sub

intSprTwo = -1
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.ConnectEventsNow()
Edward Dassmesser

Anonymous

  • Guest
script "merging"
« Reply #18 on: 2005-05-16, 09:30:02 AM »
Script stopped at line 32 on character 22: expected 'Then'
which is line
    If KeyCode = 70 Then P2Actions = P2Actions And Not ACTION_RIGHT
and it has a Then statement...

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #19 on: 2005-05-16, 11:34:16 AM »
The above post is mine, sorry wasn't logged in. Also, supposedly there's a problem on the 'forced scroll' level, someone was playing it on my computer last night and said it crashed and gave them a couple errors when they died. I haven't had time to verify this (I wasn't there when they were playing) but I'll look into it when I get home. Just figured I'd mention it incase he was right.

----added-later----
Yea, he's right, damnit...
Oh, sorry if I 'sounded' a bit pushy above, really not my intention to be. Since i've made some changes to the game itsself, I guess i'll zip it and post a link incase anyone needs it to see what im talking aobut (with the die crash thing)...
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
script "merging"
« Reply #20 on: 2005-05-17, 05:43:17 AM »
The line numbering starts from the #Split.  And I counted down the lines and saw that when the script is checking intSprTwo, it did leave out the "Then" on line 32 of the second script block.

billybob884 -no-login-

  • Guest
script "merging"
« Reply #21 on: 2005-05-17, 06:22:21 AM »
I've also noticed these 2 lines:
Code: [Select]
Const nSprWidth = 48
Const nSprHeight = 89

these just affect the 2 player sprite size right? because the 2nd player is goint to be a little bit smaller than the 1st... actually now that i think of it, im going to need to shrink both down a good bit to make it look better in 2 player, so the ultipalyer's 1st palyer will be smaller than the original, and the 2nd player will be even a little bit smaller.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #22 on: 2005-05-17, 01:04:46 PM »
Ok, i put in the Then part where it wanted it, and it opened up fine, went to the title screen, and when i went to the level select (0-4Level...) map it gave me the error

Error playing map: Display must be open to flip
[OK]

Script stopped at line 41 on character 9:
Subscript out of range
[OK]

now i believe that it's this line:
        With oLayer.Sprite(intSprTwo)

Also, i did put in the 2nd player and change the map height to 235 (which is what worked in the 2player demo i downloaded, so thats not the problem...  Is there maybe some index of errors, maybe in the help file that explains what each one could possibly pertain to, or would that not do me any good b/c it's (probably) a script error?
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
script "merging"
« Reply #23 on: 2005-05-18, 06:01:05 AM »
There is no index of errors in GameDev, but the VBScript documentation provided by Microsoft might have one.  I think you're right about this error though.  I think it's a resilt of intSprTwo being out of range.  It probably failed to find the player 2 sprite for some reason.  I would suggest adding a line of script code that helps you debug the script by showing you what it found.  You could check on the value of intSprTwo with something like this I think:
Code: [Select]

CurrentDisplay.Close
MsgBox intSprTwo

Of course you will hit a bunch of errors after that message appears because it doesn't expect the display to be closed, but at least you can find out what the value of intSprTwo is before it fails.  There are other ways too, but this is just the quickest/easiest one that came to mind.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #24 on: 2005-05-18, 06:18:35 AM »
well, if your right in the fact that it's not finding player 2, maybe the first thing i'll do is try putting the original lines that identifyed the 2player by the 0-based index. if that doesnt work then i'll try the debug thing.

----later-----
i just had a thought, could it maybe be becuase both players are on the same path, and the sprite name i specifyed also has to be the path name? i'm going to try changing that and see what happens
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #25 on: 2005-05-18, 03:36:27 PM »
ok, i havent tried the above things i said i would, but i noticed another problem... in the 2 player demo the vertical scroll margine is set a lot smaller than it would be for regular non-split screen. so theres probably goint to need to be a thing in the script to force a different vert. scroll margin for the 4 multiplayer maps.

----added-later-----
i see the 2 lines
Const nSprWidth = 32
Const nSprHeight = 32

so judging from these, would it be something like
Const VertMargin = [w/e]
?

----added-even-later-----

Ok, the 0 index thing didn't work, but I think your right about not being able to find the sprite. I happened to catch site of this line:

    Set oLayer = oMap.MapLayer(0)

Layer 0 would be the top most layer in the list on that map right? Well, if that is the layer it's looking for the 2Player sprite, it isn't going to find it. That is the background layer, the main ground where 2Player is is the next one down. So I changed it to 1 to see if that would work but it gave me some errors... the only things that stick out in my mind are something about CreateTileSet and line 31. I didn't write down the messages. So I guess that isn't right. I guess I'll try the debug thing as best I can.
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #26 on: 2005-05-18, 04:05:17 PM »
Quote from: "bluemonkmn"
There is no index of errors in GameDev, but the VBScript documentation provided by Microsoft might have one.  I think you're right about this error though.  I think it's a resilt of intSprTwo being out of range.  It probably failed to find the player 2 sprite for some reason.  I would suggest adding a line of script code that helps you debug the script by showing you what it found.  You could check on the value of intSprTwo with something like this I think:
Code: [Select]

CurrentDisplay.Close
MsgBox intSprTwo

Of course you will hit a bunch of errors after that message appears because it doesn't expect the display to be closed, but at least you can find out what the value of intSprTwo is before it fails.  There are other ways too, but this is just the quickest/easiest one that came to mind.


Ok, tried the debug thing, i put your code after

Code: [Select]
   If intSprTwo < 0 then
        For i = 0 to oLayer.SpriteCount - 1
            If oLayer.Sprite(i).rDef.Name = "Player2" then intSprTwo = i
        next
    End If


sction and it gave me a message saying
Code: [Select]
- 1
[OK]

so i tried removing that 1 little part and it gave me a string of errors ranging from CreateTileSet... to Error playing map... To Script Stopping on Line 35, so I guess that wasn't the right thing to remove.

As soon as i can find a site that will let me host files I'll rar this project with the script and put it up...
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
script "merging"
« Reply #27 on: 2005-05-18, 04:45:54 PM »
It is obvious that it is not finding the sprite.  intSprTwo is set to -1 before that bit executes, and it doesn't change.  So it is looking on the wrong layer.

I think the problem lies elsewhere, however, and not in setting oLayer = oMap.MapLayer(1).  It would be immensely easier to debug this script if you could upload the project, or, less likely, learn VBScript a bit.
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #28 on: 2005-05-18, 05:54:50 PM »
hey, thats not nice  :)


... but true...


Anyway, here is the base package (maps, gpd, bmps, & some media) ~3.7mb
(give it another 3 min to finish uploading)

Most of the vid's and some of the music was cut out b.c it would have been an ~18mb file.
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
script "merging"
« Reply #29 on: 2005-05-19, 05:37:34 AM »
For anyone else trying to download this file, the correct link is:
http://www.angelfire.com/ct3/billybob884/C-Man/Chameleon_Man.rar
(with a capital M in C-Man)

Copy and paste it 'cause AngelFire won't let you link.