Author Topic: Basics of Visual Basic  (Read 9351 times)

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #15 on: 2006-07-17, 06:55:02 PM »
Yes, I plan on creating the sprite in script. I'd like to handle a majority of that kind of stuff in script.

Now, bHitSolid will return true if the sprite hits any solid tile. Is there anything that can determine the category of tile the sprite hits? I'm going to be replacing a spear that hits ground with Spear_stuck, which the player can spring from or something. How would I do something different when a wall or hill is hit?

Also, when I ran this without any script, the spear would not recognize being on the ground whenever it was on a slant... I'm guessing it's because the spear doesn't fill the tile, and the corners are empty. I think I can get around by checking the pixels just outside the corners for solidity.

But first off, checking tile category for a sprite: how?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Basics of Visual Basic
« Reply #16 on: 2006-07-17, 09:13:35 PM »
Sprites don't have tile categories, only tiles have categories.  But maybe I misunderstood your last statement there so I'll just give you a hint in the right direction as far as tile categories go.  No time to elaborate at the moment.  You'll want to look into the TileGroup object and/or the Category object.  The Category object is basically a wrapper for a TileGroup to give it a name, associate it with a tileset, and make it save-able in a .GDP file.  But you can make your own TileGroup object and put tile index values into it to to help quickly determine whether a particular tile value on the map is in a specific set.  The easy thing, I suppose, is to define the category in the IDE and that refer to it in script via ProjectObj.Groups(...).  Then all you have to do is figure out which tile the sprite hit and check the value/index of that tile against the Category/TileGroup object to see if it's one of the tiles the spear can stick into (or you can check the individual tile indexes yourself in script).

To get a tile index at a specific coordinate in the map, use the Data property of the Layer object.  That property is documented in BMDXCtls.hlp which is in the BMDXCtls source code download.  It's basically just an array of tile values (bytes).

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #17 on: 2006-07-18, 03:04:56 AM »
I guess my last statement was a bit misleading... I was trying to say "how do I check I sprite to see if it has come in contact with a tile in a certain category."

I'm sure your post if full of all sorts of help, I've just had to back through it a few times to understand all these scripty terms. What I'm hearing is that tile categories aren't really accessible through script, that they're actually in TileGroups. And I really don't know what IDE is.

All I really want to do is have the spear stick one way when it hits flat floor, another on a hill, and another against a wall. I'm thinking it would be WAY easier just to check for solidity at the points below the bottom two corners (if both are solid, it's flat, else it's a slant) and check the points on the side to see if it hits a wall. Maybe that's just natural human arrogance talking, but I think my way's better  ;).

I guess I'm just having a hard time understanding all this new stuff. I would like to know what IDE is, though.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Basics of Visual Basic
« Reply #18 on: 2006-07-18, 05:45:01 AM »
Oh yeah, your way should work.  I just didn't know exactly what you needed.  I thought you maybe needed more than just information about which direction it hit solid at.

To clear up a couple questions: Categories and TileGroups are both available in script.  TileGroups are the data itself and Categories are the objects that contain them and link them into the project with a name and such.  IDE refers to the "Integrated Development Environment" -- a term used for many development environments.  I consider GameDev to be such an environment.  When I say IDE, I'm just referring to GameDev.exe -- the environment where you can edit your project in a user-friendly way.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #19 on: 2006-07-18, 06:50:48 AM »
Ok, so I've hit another snag. How do I create a sprite in script? From my searches and CTLR-f's, the best I've come up with is this:

Code: [Select]
Dim SpearSprite
Set SpearSprite = Lyr.pMap.SpriteDefs(Spear_in_ground_test).MakeInstance

(I already have Lyr defined)

Beyond that, I have no clue. The post about creating the realistic explosions had a bit more after that, but it didn't seem to want to work either. So what am I missing here?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Basics of Visual Basic
« Reply #20 on: 2006-07-18, 12:43:01 PM »
After creating the sprite, you need to add it to the layer.  There should be examples of this in the GoldYoink script.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #21 on: 2006-07-18, 07:46:11 PM »
Ok, I either filled in the blanks wrong, or I got the wrong piece of script:

Code: [Select]
               Dim SpearSprite
               Set SpearSprite = Lyr.pMap.SpriteDefs(Spear_in_ground_test).MakeInstance
               SpearSprite.Name = "Spear_in_ground"
               Set SpearSprite.rPath = Test1
               Set SpearSprite.rLayer = Lyr
               Set SpearSprite.Template = oMap.SpriteTemplates("Spear_in_ground")
               Test.AddSpriteDef HostObj.AsObject(SpearSprite)

It quits at the line Set SpearSprite.rPath. I'm completely unsure on this one... The Gold Yoink script didn't use MakeInstance or even AddSprite. I've also noticed that the script for realistic explosions seems like it's doing something different. It does use MakeInstance, and then some other stuff. I'm guessing there's more than one way to make a sprite.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Basics of Visual Basic
« Reply #22 on: 2006-07-18, 08:04:33 PM »
You're combining a few things here.  You're trying to make a sprite definition and a sprite instance at the same time.  What you want to be doing is just making an instance of an existing Sprite Definition, which don't have names themselves, or paths or layers or templates.  Those all exist as part of the sprite definition.  Also, you need to add the sprite to the layer.  I think all you need to do, if you already have the sprite defined, is:
Code: [Select]
Dim SpearSprite
Set SpearSprte = Lyr.pMap.SpriteDefs("Spear_in_ground_test").MakeInstance
Lyr.AddSprite(SpearSprite)
Edward Dassmesser

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #23 on: 2006-07-18, 10:48:56 PM »
Ok, so I'm getting the "Object variable or with Block variable not set" error... It's pointing at the line "Lyr.AddSprite(SpearSprite)". I think I missed putting something that should be there earlier in the script... Here's that section of script:

Code: [Select]
Sub Player_OnBeforeMoveSprites()
   Dim I
   Dim Lyr, Spr, Def
   Set Lyr = ProjectObj.Maps("Test").MapLayer("Main")
   I = 1
   Do While I<Lyr.SpriteCount
      Set Spr = Lyr.Sprite(I)
      Set Def = Spr.rDef
      If Def.Name = "Spear_test_right" Or Def.Name = "Spear_test_left" Then
         If Def.SolidTest(Spr.X, Spr.Y+32) Or Def.SolidTest(Spr.X+31, Spr.Y+32) Then
            If Def.SolidTest(Spr.x+16, Spr.Y+32) Then
               Lyr.RemoveSprite I
               Dim SpearSprite
               Set SpearSprte = Lyr.pMap.SpriteDefs("Spear_in_ground_test").MakeInstance
               Lyr.AddSprite(SpearSprite)
            Else
               Lyr.RemoveSprite I
            End If
         End If
      End If
      I = I + 1
   Loop
End Sub

And I don't know what you did Durnurd, but the concept of instance vs definition clicked with me! I'm now on the side where it's incredibly easy to understand. About 499 clicks to go before I'm good at script  :).

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Basics of Visual Basic
« Reply #24 on: 2006-07-19, 04:30:57 PM »
The error you're getting now is because one of your SpearSprite variable references is misspelled.  Put Option Explicit as the first line of (each) script to prevent these kinds of errors by forcing you to declare every variable you use.  I say "(each)" script because it needs to be after each "#Split" if you used #Split in your script at all.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Basics of Visual Basic
« Reply #25 on: 2006-07-19, 09:44:15 PM »
Oh... whoops.

Well, it works now. I just had to make it so that the spear in the ground would appear where the flying spear disappeared. And I figured it out! Thanks to that explosion script, I learned how to set the position of a sprite with .X and .Y.

Thanks guys! (And expect more cries for help)