|
Really Weird Bug in VergeC Displaying 1-6 of 6 total.
1
Gleznov
|
Hi,
I'm having a problem with one struct affecting another one. I can't figure out why this is happening. This involves my character classes (whitemage, blackmage, paladin, fighter, etc) and my actual characters used to fill my party.
First I define my class struct:
struct classTypes
{
string className;
int isWhite; // 0 if can't use White Magic, 1 if can
int isBlack; // 0 if can't use Black Magic, 1 if can
}
Next I define my character struct:
struct userChar
{
string name;
int level; // Current Level
int exp; // Total Experience
int toNext; // Total EXP needed for next level
int maxHP; // Max HP
int maxMP; // Max MP
int hp; // Hit Points
int mp; // Magic Points
int atk; // Attack Power
int def; // Defense
int agi; // Agility
int wis; // Wisdom
int eva; // Evade
int RHand; // Weapon in Right Hand
int LHand; // Weapon in Left Hand
int Head; // Armor for Head
int Body; // Armor for Body
int Misc; // Miscellaneous slot
int esper; // Esper assigned, etc
int spells[100]; // Spell slots
string chrFile; // Actual chr filename
string BattleChrFile; // Actual chr filename for battle
string FacePicFile; // Filename for char's portrait
int row; // 1 for Front, 2 for Back
int dead; // 0 if alive, 1 if dead
int isRes; // 1 if Life3'd, 0 if not
int class; // Use above #defines
}
Now I actually define my classes:
#define FIGHTER 1 // no magic
#define WHITEMAGE 2 // only white magic
#define BLACKMAGE 3 // only black magic
#define MAGE 4 // both magics
#define PALADIN 5 // only white magic
void setupClasses()
{
classes[FIGHTER].className = 'Fighter';
classes[FIGHTER].isWhite = 0;
classes[FIGHTER].isBlack = 0;
classes[WHITEMAGE].className = 'White Mage';
classes[WHITEMAGE].isWhite = 1;
classes[WHITEMAGE].isBlack = 0;
classes[BLACKMAGE].className = 'Black Mage';
classes[BLACKMAGE].isWhite = 0;
classes[BLACKMAGE].isBlack = 1;
classes[MAGE].className = 'Wizard';
classes[MAGE].isWhite = 1;
classes[MAGE].isBlack = 1;
classes[PALADIN].className = 'Paladin';
classes[PALADIN].isWhite = 1;
classes[PALADIN].isBlack = 0;
}
And finally, I define my characters - I'm only including the one here that shows the problem:
#define EDRICK 0
#define CHAR2 1
#define CHAR3 2
void setupChars()
{
// Setup Edrick
TBox(0,fb_font,classes[PALADIN].className);
Chars[EDRICK].name = 'Edrick';
// classes[PALADIN].className = 'Paladin';
TBox(0,fb_font,classes[PALADIN].className);
Chars[EDRICK].level = 1;
Chars[EDRICK].exp = 0;
Chars[EDRICK].toNext = determineNext(0);
Chars[EDRICK].maxHP = 30;
Chars[EDRICK].maxMP = 0;
Chars[EDRICK].hp = 30;
Chars[EDRICK].mp = 0;
Chars[EDRICK].atk = 2;
Chars[EDRICK].def = 2;
Chars[EDRICK].agi = 3;
Chars[EDRICK].wis = 1;
Chars[EDRICK].eva = 1;
Chars[EDRICK].RHand = EMPTYHANDED;
Chars[EDRICK].LHand = EMPTYHANDED;
Chars[EDRICK].Head = EMPTYHANDED;
Chars[EDRICK].Body = EMPTYHANDED;
Chars[EDRICK].Misc = EMPTYHANDED;
Chars[EDRICK].Esper = 0;
Chars[EDRICK].isRes = 0;
Chars[EDRICK].class = PALADIN;
int ticker;
for (ticker=0;ticker<100;ticker++)
{
Chars[EDRICK].Spells[ticker] = 0;
}
Chars[EDRICK].chrFile = 'plCecil.chr';
Chars[EDRICK].BattleChrFile = 'plCecil_Fight.chr';
Chars[EDRICK].FacePicFile = 'plCecil_Portrait.png';
Chars[EDRICK].Row = 1;
Chars[EDRICK].Dead = 0;
}
Now here's the kicker - in the above, note these lines of code:
// Setup Edrick
TBox(0,fb_font,classes[PALADIN].className);
Chars[EDRICK].name = 'Edrick';
// classes[PALADIN].className = 'Paladin';
TBox(0,fb_font,classes[PALADIN].className);
TBox prints a textbox with the third parameter as text to the screen. When I run this, here's the two printouts I get back to back:
'Paladin'
'Edrick'
At this point in time, classes[PALADIN].className = 'Edrick'.
Now what's also disturbing is that if I uncomment the next line down and reset classes[PALADIN].className = 'Paladin' again, then at that moment in time, Chars[EDRICK].name = 'Paladin' as well. I can't keep the two separate - classes[PALADIN].className is insisting on being equal to Party[EDRICK].name and vice versa.
This is absolutely blowing my mind. Is there a massive bug in Verge that could explain this? Am I doing something wrong? WTF?
Thanks!
Gleznov
Posted on 2005-10-21 07:39:39
|
Gleznov
|
OK, ready for part 2?
So I decided to get around this problem temporarily, I would integrate the class struct into the char struct. Slightly uglier and bulkier, but let's do it. I unincluded Class.vc and Classes.vc which contained the code listed in the above sections. I altered my character struct to be as follows:
struct userChar
{
string name;
int level; // Current Level
int exp; // Total Experience
int toNext; // Total EXP needed for next level
int maxHP; // Max HP
int maxMP; // Max MP
int hp; // Hit Points
int mp; // Magic Points
int atk; // Attack Power
int def; // Defense
int agi; // Agility
int wis; // Wisdom
int eva; // Evade
int RHand; // Weapon in Right Hand
int LHand; // Weapon in Left Hand
int Head; // Armor for Head
int Body; // Armor for Body
int Misc; // Miscellaneous slot
int esper; // Esper assigned, etc
int spells[100]; // Spell slots
string chrFile; // Actual chr filename
string BattleChrFile; // Actual chr filename for battle
string FacePicFile; // Filename for char's portrait
int row; // 1 for Front, 2 for Back
int dead; // 0 if alive, 1 if dead
int isRes; // 1 if Life3'd, 0 if not
int class; // Use above #defines
// The following should be in Class.vc, but it wasn't working - this is a fix
string className;
int isWhite; // 0 if can't use White Magic, 1 if can
int isBlack; // 0 if can't use Black Magic, 1 if can
}
Now I define my character - once again, more stupid problems:
#define EDRICK 0
#define KAIN 1
#define GLEZNOV 2
#define DKCECIL 3
#define TELLAH 4
// FIX
// This is a fix for the Class.vc/Classes.vc disaster
#define FIGHTER 1 // no magic
#define WHITEMAGE 2 // only white magic
#define BLACKMAGE 3 // only black magic
#define MAGE 4 // both magics
#define PALADIN 5 // only white magic
// END FIX
void setupChars()
{
// Setup Edrick
Chars[EDRICK].name = 'Edrick';
Chars[EDRICK].level = 1;
Chars[EDRICK].exp = 0;
Chars[EDRICK].toNext = determineNext(0);
Chars[EDRICK].maxHP = 30;
Chars[EDRICK].maxMP = 0;
Chars[EDRICK].hp = 30;
Chars[EDRICK].mp = 0;
Chars[EDRICK].atk = 2;
Chars[EDRICK].def = 2;
Chars[EDRICK].agi = 3;
Chars[EDRICK].wis = 1;
Chars[EDRICK].eva = 1;
Chars[EDRICK].RHand = EMPTYHANDED;
Chars[EDRICK].LHand = EMPTYHANDED;
Chars[EDRICK].Head = EMPTYHANDED;
Chars[EDRICK].Body = EMPTYHANDED;
Chars[EDRICK].Misc = EMPTYHANDED;
Chars[EDRICK].Esper = 0;
Chars[EDRICK].isRes = 0;
Chars[EDRICK].class = PALADIN;
int ticker;
for (ticker=0;ticker<100;ticker++)
{
Chars[EDRICK].Spells[ticker] = 0;
}
Chars[EDRICK].chrFile = 'plCecil.chr';
Chars[EDRICK].BattleChrFile = 'plCecil_Fight.chr';
Chars[EDRICK].FacePicFile = 'plCecil_Portrait.png';
Chars[EDRICK].Row = 1;
Chars[EDRICK].Dead = 0;
// FIX
// This is a fix for the Class.vc disaster
Chars[EDRICK].className = 'Paladin';
Chars[EDRICK].isWhite = 1;
Chars[EDRICK].isBlack = 0;
// END FIX
}
Now here's where it crashes out:
Chars[EDRICK].className = 'Paladin';
with the error:
Could not resolve identifier className!
I have several chars defined, so I wanted to see if it was all the new fields (isWhite and isBlack as well) so I commented out that one line and ran it again, and isWhite/isBlack are no problem, but the next char's Chars[charname].className = ''; yields the same error.
Can you not have more than one string in a struct? What's going on here? I can't even work around?
Glez
Posted on 2005-10-21 08:35:41
|
Omni
|
I don't know much about what causes a V3 struct error, but I've run into one once or twice before...
In my case, I simply started over. I mean, I didn't recode everything, but I opened a new VC project, and slowly reinserted all the code. Starting with the 'broken'/'suspicious' code first, so I can make sure whether or not it's Verge for messing up all the struct data, or me for forgetting something simple. Putting just the suspicious code in helps to simplify.
Then reinsert the other code. Strangely, one or two errors I find tend to simply disappear after such testing, and I never have the same problem again.
Try recreating the two classes with just the classname property and then running the string tests. Maybe you'll find out something interesting and useful.
Posted on 2005-10-21 09:09:30
|
Gleznov
|
Well as an insert to part two, now it's not liking 'isWhite' or 'isBlack' either - screw it. I'm hard-coding my system to run switch statements on the class and write the name according to that. Which is only really bad because it means I'll be less likely to want to release all this as a framework in the future.
I'd go with your idea, but I have so many modules that are dependant on other modules that the simplest I could get it down would still be fairly ugly. I'd rather just work-around. Thanks though, at least I know there are Verge struct errors that exist. Makes me feel more sane.
Glez
Posted on 2005-10-21 09:18:15
|
Gayo
|
V3 used to have some really fucky struct errors, but I thought they had been fixed. Hrm, looks like there were more problems lurking around! Weird.
Posted on 2005-10-21 17:08:05
|
Jesse
|
Quote: Originally posted by Gleznov
Hi,
I'm having a problem with one struct affecting another one.
// Setup Edrick
TBox(0,fb_font,classes[PALADIN].className);
Chars[EDRICK].name = 'Edrick';
// classes[PALADIN].className = 'Paladin';
TBox(0,fb_font,classes[PALADIN].className);
You didn't show the actual declaration of the global variables classes and Chars, but I bet you're accessing the index PALADIN == 5 in a struct that is only 5 long, and so only has indexes 0 to 4. In my tests, this can cause modifications in the other struct.
I can't replicate the other bug. Send me your code and I'll take a look at it, if you like. If it's a verge bug, I'd like to squash it.
Posted on 2005-10-21 18:53:31 (last edited on 2005-10-21 19:01:17)
|
Displaying 1-6 of 6 total.
1
|
|