Sign in to follow this  

Main Game Logic Error

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on my Game Logic for awhile but when I went to go compile it, it said I have errors can someone help me out. Here is the first part that is having a error problem(This is in VB6)
Function GetPlayerName(ByVal Index As Long) As String
    GetPlayerName = Trim(Player(Index).Name)
End Function
It says that
(Player(Index..
Is not right says that it's not defined right, I can post my whole Game Logic if it will help me get this error fixed. Please Someone help me! ~ARC.inc

Share this post


Link to post
Share on other sites
Quote:
Original post by ARC inc
It says that (Player(Index.. Is not right says that it's not defined right

Then Player isn't defined right. You'd need either of

1. Player is an array containing at least Index + 1 instances of a Type or class-module containing a Name member of type String (or that can can be implicitly cast such).
2. Somewhat more perversely, Player may be a function taking an Integer argument and returning an instance of a class as described in 1.

We can't verify this without seeing a definition of Player and a declaration of its type. And for the record, this is a syntax error, not a logic error.

Admiral

Share this post


Link to post
Share on other sites
Ok, here is my Game Logic as it stands right now.

Function GetPlayerName(ByVal Index As Long) As String
GetPlayerName = Trim$(Player(Index).Name)
End Function

Sub SetPlayerName(ByVal Index As Long, ByVal Name As String)
Player(Index).Name = Name
End Sub

Function GetPlayerClass(ByVal Index As Long) As String
GetPlayerClass = Player(Index).Class
End Function

Sub SetPlayerClass(ByVal Index As Long, ByVal ClassNum As String)
Player(Index).Class = ClassNum
End Sub

Function GetPlayerSprite(ByVal Index As Long) As String
GetPlayerSprite = Player(Index).Sprite
End Function

Sub SetPlayerSprite(ByVal Index As Long, ByVal Sprite As Long)
Player(Index).Sprite = Sprite
End Sub

Function GetPlayerLevel(ByVal Index As Long) As String
GetPlayerLevel = Player(Index).Level
End Function

Sub SetPlayerLevel(ByVal Index As Long, ByVal Level As String)
Player(Index).Level = Level
End Sub

Function GetPlayerExp(ByVal Index As Long) As String
GetPlayerExp = Player(Index).EXP
End Function

Sub SetPlayerExp(ByVal Index As Long, ByVal EXP As String)
Player(Index).EXP = EXP
End Sub

Function GetPlayerAccess(ByVal Index As Long) As String
GetPlayerAccess = Player(Index).Access
End Function

Sub SetPlayerAccess(ByVal Index As Long, ByVal Access As String)
Player(Index).Access = Access
End Sub

Function GetPlayerHP(ByVal Index As Long) As String
GetPlayerHP = Player(Index).HP
End Function

Sub SetPlayerHP(ByVal Index As Long, ByVal HP As String)
Player(Index).HP = HP
If GetPlayerHP(Index) > GetPlayerMaxHP(Index) Then
Player(Index).HP = GetPlayerMaxHP(Index)
End If
End Sub

Function GetPlayerSP(ByVal Index As Long) As String
GetPlayerSP = Player(Index).SP
End Function

Sub SetPlayerSP(ByVal Index As Long, ByVal SP As String)
Player(Index).SP = SP
If GetPlayerSP(Index) > GetPlayerMaxSP(Index) Then
Player(Index).SP = GetPlayerMaxSP(Index)
End If
End Sub

Function GetPlayerMP(ByVal MP As Long) As String
GetPlayerMP = Player(Index).MP
End Function

Sub SetPlayerMP(ByVal Index As Long, ByVal MP As String)
Player(Index).MP = MP
If GetPlayerMP(Index) > GetPlayerMaxMP(Index) Then
Player(Index).MP = GetPlayerMaxMP(Index)
End If
End Sub

Function GetPlayerMaxHP(ByVal Index As Long) As String
GetPlayerMaxHP(Index).MaxHp
End Function

Function GetPlayerMaxSP(ByVal Index As Long) As String
GetPlayerMaxSP(Index).MaxSP
End Function

Function GetPlayerMaxMP(ByVal Index As Long) As String
GetPlayerMaxMP = Player(Index).MaxMP
End Function

Function GetPlayerSTR(ByVal Index As Long) As String
GetPlayerSTR = Player(Index).STR
End Function

Sub SetPlayerSTR(ByVal Index As Long, ByVal STR As String)
Player(Index).STR = STR
End Sub

Function GetPlayerDEF(ByVal Index As Long) As String
GetPlayerDEF = Player(Index).DEF
End Function

Sub SetPlayerDEF(ByVal Index As Long, ByVal STR As String)
Player(Index).DEF = DEF
End Sub

Function GetPlayerSPEED(ByVal Index As Long) As String
GetPlayerSPEED = Player(Index).Speed
End Function

Sub SetPlayerSPEED(ByVal Index As Long, ByVal Speed As String)
Player(Index).Speed = Speed
End Sub

Function GetPlayerMAGI(ByVal Index As Long) As String
GetPlayerMAGI = Player(Index).MAGI
End Function

Sub SetPlayerMAGI(ByVal Index As Long, ByVal MAGI As String)
Player(Index).MAGI = MAGI
End Sub

Function GetPlayerPOINTS(ByVal Index As Long) As String
GetPlayerPOINTS = Player(Index).POINTS
End Function

Sub SetPlayerPOINTS(ByVal Index As Long, ByVal POINTS As String)
Player(Index).POINTS = POINTS
End Sub

Function GetPlayerMap(ByVal Index As Long) As String
GetPlayerMap = Player(Index).MAP
End Function

Sub SetPlayerMap(ByVal Index As Long, ByVal MAP As String)
Player(Index).MAP = MAP
End Sub

Function GetPlayerX(ByVal Index As Long) As String
GetPlayerX = Player(Index).X
End Function

Sub SetPlayerX(ByVal Index As Long, ByVal X As String)
Player(Index).X = X
End Sub

Function GetPlayerY(ByVal Index As Long) As String
GetPlayerY = Player(Index).y
End Function

Sub SetPlayerY(ByVal Index As Long, ByVal y As String)
Player(Index).y = y
End Sub

Function GetPlayerDir(ByVal Index As Long) As String
GetPlayerDir = Player(Index).Dir
End Function

Sub SetPlayerDir(ByVal Index As Long, ByVal Dir As String)
Player(Index).Dir = Dir
End Sub

Function GetPlayerInvItemNum(ByVal Index As Long) As String
GetPlayerInvItemNum = Player(Index).Inv(InvSlot).Num
End Function

Sub SetPlayerInvItemNum(ByVal Index As Long, ByVal InvSlot As Long, ByVal ItemNum As Long)
Player(Index).Inv(InvSlot).Num = ItemNum
End Sub

Function GetPlayerInvItemValue(ByVal Index As Long, ByVal InvSlot As Long) As Long
GetPlayerInvItemValue = Player(Index).Inv(InvSlot).Value
End Function

Sub SetPlayerInvItemValue(ByVal Index As Long, ByVal InvSlot As Long, ByVal ItemValue As Long)
Player(Index).Inv(InvSlot).Value = ItemValue
End Sub

Function GetPlayerInvItemDur(ByVal Index As Long, ByVal InvSlot As Long) As Long
GetPlayerInvItemDur = Player(Index).Inv(InvSlot).Dur
End Function

Sub SetPlayerInvItemDur(ByVal Index As Long, ByVal InvSlot As Long, ByVal ItemDur As Long)
Player(Index).Inv(InvSlot).Dur = ItemDur
End Sub

Function GetPlayerArmorSlot(ByVal Index As Long) As Long
GetPlayerArmorSlot = Player(Index).ArmorSlot
End Function

Sub SetPlayerArmorSlot(ByVal Index As Long, InvNum As Long)
Player(Index).ArmorSlot = InvNum
End Sub

Function GetPlayerWeaponSlot(ByVal Index As Long) As Long
GetPlayerWeaponSlot = Player(Index).WeaponSlot
End Function

Sub SetPlayerWeaponSlot(ByVal Index As Long, InvNum As Long)
Player(Index).WeaponSlot = InvNum
End Sub

Function GetPlayerHelmetSlot(ByVal Index As Long) As Long
GetPlayerHelmetSlot = Player(Index).HelmetSlot
End Function

Sub SetPlayerHelmetSlot(ByVal Index As Long, InvNum As Long)
Player(Index).HelmetSlot = InvNum
End Sub

Function GetPlayerShieldSlot(ByVal Index As Long) As Long
GetPlayerShieldSlot = Player(Index).ShieldSlot
End Function

Sub SetPlayerShieldSlot(ByVal Index As Long, InvNum As Long)
Player(Index).ShieldSlot = InvNum
End Sub

Function GetPlayerGloveSlot(ByVal Index As Long) As Long
GetPlayerGloveSlot = Player(Index).GloveSlot
End Function

Sub SetPlayerGloveSlot(ByVal Index As Long, InvNum As Long)
Player(Index).GloveSlot = InvNum
End Sub

Function GetPlayerBootSlot(ByVal Index As Long) As Long
GetPlayerBootSlot = Player(Index).BootSlot
End Function

Sub SetPlayerBootSlot(ByVal Index As Long, InvNum As Long)
Player(Index).BootSlot = InvNum
End Sub


Now I got told to Define my Player like this

Public MyIndex As Long

'declaring Player
Private Type tPlayer
Name As String
End Type


Now that works for the Player, but I just don't think that it will work, also This game logic does somewhat come from Mirage Game Source. I lost it so I'm not postive on how to define it.

Share this post


Link to post
Share on other sites
What is Public MyIndex As Long for?
I think you do not really need it.

Player can be (the following code must be declared in a global scope, e.g. out of any function):

'declaring Player
Private Type tPlayer
Name As String,
Class As String,
Sprite As String,
... (other members here)
End Type

Const MAX_NUMBER_OF_PLAYERS = 100

Dim Player(MAX_NUMBER_OF_PLAYERS) As tPlayer



I do not know if "game logic" is the right way to call the code you posted. I would name it as (not necessary) set of utility functions.

Anyway, I suggest you not to use other people's code that you do not understand, and to define by yourself what you really need. Game logic and any other part of another program shall not be included in your project, unless you clearly see that it is the same that you would write by yourself. Use other people's work as inspiration, not as a solution.

[edit lang="vb"]

[Edited by - Nyarlath on October 5, 2007 2:17:01 AM]

Share this post


Link to post
Share on other sites
dude......honestly..... have u not read any other posts on this forum??? please edit your post and put in the appropriate source tags! click 'faq' for help!

Share this post


Link to post
Share on other sites
Well that worked thanks, now I'm getting more errors, but I'll work them out. Also I do understand the code I just didn't remember how they defined it. As anyone will tell you "Don't Reinvent the Wheal" So why re-make something when it's there to use for free?

Share this post


Link to post
Share on other sites

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this