Author Topic: Hurt Demo script, pasted into COM, error  (Read 6241 times)

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« on: 2005-11-03, 09:57:24 PM »
One of those errors that I don't understand.  I want enemies and the player to flash for a few frames whenever they get hurt.  I used the hurt demo as a reference and pasted it into my vb6.0 project and changed all the variable names and made it universal to work on any sprite:
Code: [Select]
Public Sub DrawHurtTilesOverSprite(ByVal Spr As Sprite)
  Dim TS As TileSetDef
  With Spr
    Set TS = ProjectObj.TileSetDef(.CurTSDef.GetIndex + 11) '11 being separation between corresponding tilesets
    If Not TS.IsLoaded Then
      TS.Load
    End If
    If TS.LoadedInstance Is Nothing Then
      Set TS.LoadedInstance = DllDisp.CreateTileSet(TS.Image, TS.TileWidth, TS.TileHeight)
    End If
    DllDisp.DrawTile TS.LoadedInstance, .CurTile, .X - GdPlayer.MapScrollX, .Y - GdPlayer.MapScrollY, 0, 0, 640, 480, True
  End With
End Sub
Code: [Select]
Sub Player_OnSpritesCollide(Name, ClsAIdx, ClsBIdx, CollDefIdx)
   Hurt = 100
End Sub

Sub Player_OnBeforeMoveSprites()
   Dim TS

   If Hurt > 0 Then
      Hurt = Hurt - 1
      If Hurt Mod 2 = 1 Then
         With ProjectObj.GamePlayer
            Set TS = ProjectObj.TileSetDef("tsHurt")
            If Not TS.IsLoaded Then
               TS.Load
            End If
            If TS.LoadedInstance Is Nothing Then
               Set TS.LoadedInstance = CurrentDisplay.CreateTileSet( _
                  TS.Image, TS.TileWidth, TS.TileHeight)
            End If
            CurrentDisplay.DrawTile _
               TS.LoadedInstance, _
               .PlayerSprite.CurTile, _
               .PlayerSprite.X - .MapScrollX, _
               .PlayerSprite.Y - .MapScrollY, _
               0, 0, 640, 480, True
         End With
      End If
   End If
End Sub

I have the hurt demo script on the bottom for reference.  (I run my code every other frame if the sprite is hurt using the same event as the hurt demo)

my error message is :
Run-time error '-2147418113 (8000ffffy)'
Method 'Image' of object 'TileSetDef' failed

Everything seems to work good except any time I call TS.image, i get that error (i even put it in a line by itself)  I've confirmed that TS.IsLoaded is True and TS.TileWidth has a value (32)

I even set the TS to a tileset I KNOW is loaded (the TS of the playersprite) and I still get the same error.
I've also tried breaking the lines into multipul lines and dimming the varibles different, but nothing seems to work.  I see that .Image is actually a Property and not a Method like VB seems to think, maybe this is the problem, but I don't know how to fix it.


Anyone know what to do or try? ($50 says bluemonk posts with a brillant easy solution :P )

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #1 on: 2005-11-04, 07:09:38 AM »
Hmm, I feel pressured to come up with a brilliant easy solution now :).

Anyway, the first thing that comes to mind if you're using code similar to some script code that worked is that there might be a problem with process boundaries.  VBScript code runs in the same process as GDPlay.exe, but VB6 EXE code runs in a separate process and all the data that goes back and forth between GameDev and the VB6 exe has to be "marshalled" accross process boundaries (which is slow, BTW, so I would suggest avoiding the use of VB6 executables as a method of customizing GameDev games, or at least minimize traffic between GDPlay and your EXE if you do).  The problem is, I think, that some things cannot be marshalled accross process boundaries.  I think one of these types was fonts.  If you create a font in your VB6 process and try to set the display font in GDPlay, I think it doesn't work.  The solution was to do one of the following:

1) Use a VB6 dll instead of a VB6 exe, and create the instance of the DLL's main object and hook it up to GameDev from VBScript (I can help with this if it's not clear how to do that)

2) Umm... I may have miscounted the number of solutions I have :).  I was going to suggest using Engine.NewGameDevObj instead of the CreateObject or New statement within VB6, but you're not using either of those as far as I can tell.

I'm not sure that this is your problem, but it's one thing to consider.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #2 on: 2005-11-04, 05:46:37 PM »
I am actually using a dll already, my .exe just creates a GameDevPlayer.Engine, Loads my .gdp into that engine and passes it on to my dll so it can start capturing events.  (you taught me how to do this a year and a half ago)
I'll wait to see if you can find a solution, since I tried everything that makes sense to me.  I could send you the project if need be.  It should zip up pretty small.

I do have another method of creating this effect I could implement.  Just generate a new sprite/template identical to the hurt sprite except the tileset name would change for all states/frames, and make it "simple/scripted" so it draws over the top of the orignal sprite, and just adjust the new sprite's velocity, position, and state as often as needed.

Anyways, thanks for the reply, Ill check back.:)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #3 on: 2005-11-05, 10:05:49 AM »
*-) Hmmm... Perhaps the means by which you loaded your DLL caused it to be loaded into a separate process.  Did you load the DLL into the EXE or somehow load it into GameDev?  Hopefully I was thinking clearly when I told you how load load the DLL and I either told you to use Script or to use the NewGameDevObj call to load your DLL.

It might save me a good deal of time if you can zip up something relatively small to show me the problem.  I'll wait for a file.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #4 on: 2005-11-05, 01:41:46 PM »
I just sent you a link.  Thanks for the help.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #5 on: 2005-11-06, 06:25:56 PM »
Where did you send it? I don't see it.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #6 on: 2005-11-06, 10:21:04 PM »
your @mail.com email address.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #7 on: 2005-11-07, 06:44:22 AM »
Didn't that get bounced back?  That mailbox is full and not accepting any more email.  Did I leave that old address out there somewhere that I shouldn't have?  My new email address is linked to my name at the top of the GameDev homepage, and it should be updated everywhere in the documentation and about dialogs in the latest version of GameDev.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #8 on: 2005-11-07, 05:26:38 PM »
I grabbed it from your msn link. :?   I figured the return message was becuase I tried to send it with an attachment the first time.

anyways, hopefully you get it now, I PMed you.

Thanks for the help ahead of time.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #9 on: 2005-11-07, 09:35:39 PM »
Ah, my MSN link.  So you decided to just overlook my email link next to it and use the MSN link eh? ;)  I don't know of a good way to change my MSN account's email address without just creating a new account, so I left that one as is.  If you have an idea there, let me know.  Eventaully I might just bite the bullet and create a new passport/account using my new email address.  Except I have a lot of things linked to that passport with the email.com address, including my MSDN membership and MCP certification.

Well, concerning your original question, good news mostly:
  • I compiled and ran the code you sent and it worked fine with the "D" -- touch the enemy and I got a flashing D.
  • I commented out the "D" and Exit Sub, and compiled and ran again and got a type mismatch because the DLL was out of synch with the EXE
  • I recompiled the EXE and ran again, and touched the knight, and to my surprise, it worked fine.  We flashed red.
  • I pondered this result for a moment and tried running from the VB6 IDE instead of compiling and running externally.  Then I saw the error you described.


I think the explanation is similar to what I was describing earlier.  When the IDE is debugging the DLL, I think it loads the DLL into vb6.exe (the IDE) in order to try to pretend to be the DLL.  Since this is a separate process from GDPlay.exe/GameDev.exe, it has problems when trying to use objects that can't be passed accross process boundaries.  I'm not sure this is exactly what's happening, but it's my best effort at an explanation.  Nevertheless, the solution is simply to not run the DLL in the IDE.  That's the one piece of bad news -- no really nice way to debug the DLL.  Of course with the full screen display there never really was a nice way to debug the DLL in the first place.

There's your "brilliant easy solution" :). Hope that helps.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #10 on: 2005-11-07, 10:59:24 PM »
Did what you did.  And I got it to work too.


Since I compile it in the IDE about every 5 minutes when im working on the game, I guess Ill just have to comment this sub out while im working on it.  Unless of course there is some way for the dll to know whether its running in the IDE or standalone, and i can make the appropriate separate code paths:)

Thanks a lot.  I knew it was something simple that I was missing.  Too bad noone took the bet ;D

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #11 on: 2005-11-08, 06:26:39 AM »
The following declaration and code block can be used to determine the executable into which your DLL was loaded.  I just verified that it returns the full path to VB6.exe (including "VB6.exe" at the end) when running in the debug environment, and it returns the full path to GDPlay.exe when running in a compiled environment:
Code: [Select]

Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

   Dim FileName As String
   FileName = Space(512)
   GetModuleFileName 0, FileName, Len(FileName)
   FileName = Left$(FileName, InStr(FileName, Chr$(0)) - 1)
So you can use that to determine when you're running in a debug encironment.  But wouldn't it also be easy to get in the habit of using the "Make" command instead of the run command?  You don't have to close the VB6 IDE, you just have to run the EXE outside the IDE (kind of like running a scripted GDP outside of GameDev).

If the Type Mismatch error gets to be troublesome, I can probably show you how to make the EXE not have to care about early-binding to the DLL, which is what causes it to have problems when the DLL is re-compiled without binary compatibility.  Then you could just have your workspace contain only the DLL.  When you want to run, you just compile the DLL and then run the EXE outside the IDE.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #12 on: 2005-11-08, 07:03:18 PM »
Thanks for the code, It works perfectly.

After trying it out a few times, I see that using the make command is just as easy as using the run command, except the lack of keyboard shortcut.

There is also a "make project" command which does the exe and dll at the same time, so the binary compatability thing shouldn't be something to worry about as far as design is concerned.  I think I know how to do it though, edit the .dll properties for binary compatiability to the last version.

Another interesting thing I noticed is how much faster the code executes.  I had a debug mode that collected a lot of data and drew it on the screen every frame.  When entering this mode, I would get about a 1/2 drop in framerates in the IDE.  With the compiled dll there is not even a noticable slowdown :o not even a studder, ever.

I knew a compiled dll would be faster, and i've seen it increase performance in another project, but I never noticed this much before.

I have even been designing this project from the begining to run at 30 fps since there was going to be so much per frame code and action, I didn't want any slowdowns.  It looks like a might be able to go back to 60 if I desire  :)  

Thanks for the help.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Hurt Demo script, pasted into COM, error
« Reply #13 on: 2005-11-08, 07:27:52 PM »
Another thing.  When my playersprite bounces off the enemies due to sprite collision def that "Repels" the player sprite past his normal max velocity, there seems to be a problem with the red drawn over tile lining up with the playersprite tile.  The red tile seems to lead the playersprite.  I tried it in the OnAfterMoveSprites and OnBeforeMoveSprites Events, and it seems to line up better in the Before, but still seems to be a bit off.  I also haven't tried the OnFrameStart event yet.

This can be an acceptable bug for now, and ill try to fix it when I go back and start polishing the project.

edit - when player sprite is still or moving slow, it seems to draw perfectly.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Hurt Demo script, pasted into COM, error
« Reply #14 on: 2005-11-09, 06:53:17 PM »
It should be right on if you do it in OnBeforeMoveSprites because GameDev draws the display (map and sprites), then raises the OnBeforeMoveSprites event, then advances all the sprite positions, then raises OnAfterMoveSprites, then flips the drawn buffer to the visible display.  So there should have been no movement between the time the sprites were drawn and the time when you draw your red frame on top.