Scrolling Game Development Kit Forum

SGDK Version 1 => Script => Topic started by: bat on 2006-08-25, 10:00:24 PM

Title: basic vb stuff
Post by: bat on 2006-08-25, 10:00:24 PM
Quote from: bluemonkmn on 2006-08-15, 09:41:41 am
You need to put "Option Explicit" at the top of your script to force you to declare variables before you try to use them.  Then you also need to initialize "Target" and "ninja" since you never set those variables to anything befor trying to use them as if they were variables representing sprites.

how do you declare/initialize variables in VB? and is there a command that "grabs" a sprite that is not your main character and lets you use it as a variable?
Title: Re: basic vb stuff
Post by: bluemonkmn on 2006-08-26, 07:41:41 AM
1) To declare a variable use "Dim"
2) To initialize a variable use "=" to set it to a value
3) To get an object from a GameDev function and put it into a variable use "Set".  For example, the Sprites collection of the layer object can give you any sprite object, and you use "Set" to put the sprite into a variable if you want to keep it in a variable instead of in the Sprite collection for some reason.

Look at some existing scripts to see how they use "Dim", "=" and "Set".
Title: Re: basic vb stuff
Post by: bat on 2006-08-26, 12:33:45 PM
thanks!
Title: Re: basic vb stuff
Post by: bat on 2006-08-28, 11:22:12 PM
o...k.... um... i tried to do all you said, but i'm getting messages telling me i forgot sub/end ect... here's the script below: (i'm totally confused)
Title: Re: basic vb stuff
Post by: bat on 2006-08-29, 12:40:13 AM
Option Explicit

Sub Player_OnPlayInit()
Dim target
AngleRadians=0
for i = 0 to 1
   set target(i) = new target
   target(i).target "city","target" & i, 1

   target.X = player.X + Cos(AngleRadians) * 100
   target.Y = player.Y - Sin(AngleRadians) * 100
  next
 if ACTION_BUTTON3 then AngleRadians = AngleRadians + 3.14159265 / 18
  End If
end sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
Title: Re: basic vb stuff
Post by: bluemonkmn on 2006-08-29, 06:57:19 PM
You don't need an "End If" when you put code on the same line as the "Then".  If you do that, the "If" automatically ends at the end of the line.
Title: Re: basic vb stuff
Post by: durnurd on 2006-08-29, 08:04:24 PM
There are so many things I could say about this, I don't know where to begin.

First, this code only executes once, at the beginning of game execution.  You want most of this code to execute at the beginning of the level, and some of it to only execute on controller move.  You'll need to also declare AngleRadians as a variable, and move it to a global scope. 

What is this "target" object that you seem to be creating (with target(i) = new target)?  Any object not built in to SGDK you need to declare yourself.  However, I think all you are really trying to do is create a sprite called target.

The check for ACTION_BUTTON3 will always return true, since ACTION_BUTTON3 is a constant value not equal to false (0).  You need to check:  if NewActions And ACTION_BUTTON3 to check to see if they are currently pressing the button.

Also, the check for ACTION_BUTTON3 needs to go into a Player_OnControllerMove sub instead of OnPlayInit.

You will also want to declare Target as an array, rather than a single variable.
Title: Re: basic vb stuff
Post by: bat on 2006-09-05, 04:29:45 PM
http://gamedev.comdel.net/index.php?topic=842.msg3692#msg3692 (http://gamedev.comdel.net/index.php?topic=842.msg3692#msg3692)
ok.. i give up for now... how (exactly) would i code this?
(i really need to get a vb script for dummies book... lol)   ;D
Title: Re: basic vb stuff
Post by: bat on 2006-09-06, 10:29:58 PM
i don't know how to script the thing in the link, even though half of its already there... can some one help?
Title: Re: basic vb stuff
Post by: bat on 2006-09-07, 06:56:03 PM
quote: What is this "target" object that you seem to be creating (with target(i) = new target)?  Any object not built in to SGDK you need to declare yourself.  However, I think all you are really trying to do is create a sprite called target.


yes! a sprite callled target... how? i made the sprite in the wysiwyg edtior but how do i control it with script?

Title: Re: basic vb stuff
Post by: bat on 2006-09-07, 07:33:58 PM
current fix ( i know not all is right... still need to know about the sprite thing)


Option Explicit

Sub Player_OnControllerMove
AngleRadians=0
target.X = player.X + Cos(AngleRadians) * 100
target.Y = player.Y - Sin(AngleRadians) * 100
next
if ACTION_BUTTON3 and NewActions then AngleRadians = AngleRadians+ 3.14159265/8
end sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
Title: Re: basic vb stuff
Post by: bluemonkmn on 2006-09-08, 10:36:54 AM
Try adding this before your first reference to "target":
Code: [Select]
Dim target
Dim player
Set target = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(1)
Set player = ProjectObj.GamePlayer.PlayerSprite
That will create a variable called "target" and set it to refer to sprite number 1 (the second sprite) on the player's layer.  (It will also create a variable called "player" and make it refer to the player sprite -- usually people just refer to it directly instead of keeping it in a variable though.)  I'm just guessing at a number here because I don't know if number 1 is going to be your target sprite or not.  It might end up moving the player or some other sprite (if you have others) instead.  But you get the idea.  If you want to be sure you found the right sprite, the correct way is to loop through the sprites in the layer and look for one whose definition's name matches the name of your target sprite definition.  But I don't want to take the time to show how to do that right now if it's not necessary.  If 1 is the wrong number, you can try 0 or try figuring out how to loop through sprites to find the right one.  Often times when a sprite is controlled through script, it's also created by script so it doesn't have to deal with this problem (because when you create a sprite in script, you get a reference to the created sprite automatically).  That's what the scripting wizard does when it writes script that creates bullet sprites.
Title: Re: basic vb stuff
Post by: bat on 2006-09-11, 05:46:03 PM
great! i'll try it!  ;D
Title: Re: basic vb stuff
Post by: bat on 2006-09-18, 10:14:52 PM
wut did you say durn, about the angle rads having to be globol or something??