A bug...maybe?
Displaying 1-12 of 12 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Rysen

I'm currently coding all the timing functions for Rysen Ranch and ran into a problem...I'm not sure if it's a bug or if I'm just doing something n00bish.

My problem is that it seems I cannot assign string variables values in a HookTimered or HookRetraced function. (I haven't tried it with the other Hook* functions). In some cases I've been able to avoid it but there are some cases where I just don't think I can avoid it.

For example, if I have something like:
if(time.DayTime==1)
{
    time.PartOfDay="PM"; // This will crash
}
If(time.minCount<10)
{
   time.col=":0"; //So will this
}

If I comment out the assignments it works fine, but I don't get a nifty 00:00 time format, and I can't tell the player if it's AM or PM ;_;

I'm basically using the same function from my winv2 version, so I assumed that it would still work with v3.

Any ideas? ^_^

Posted on 2004-05-06 18:51:09

mcgrue

They are strings in the struct, right? :D

Posted on 2004-05-06 20:27:46

Rysen

Yeah, I double checked that. :P

Posted on 2004-05-06 20:36:57

mcgrue

Is this a runtime crash or a compiletime crash?

Posted on 2004-05-06 20:41:23

Rysen

Runtime.

Rethinking what it is I need to do though, I think I can get away without having to assign string variables, but still, I don't think it should crash if tried. ^_^

Posted on 2004-05-06 20:42:06 (last edited on 2004-05-06 20:47:39)

mcgrue

Just out of curiosity, have you attempted to call the function in your autoexec or something, so it runs without being hooktinered?

Posted on 2004-05-06 21:04:38

Rysen

Just tried that, still crashes, so it's not a problem with hook's then.

I added a bunch of Log()'s, and appearntly I was wrong in my statement that:
if(time.DayTime==1)
{
   time.PartOfDay="PM";
}

crashes because it doesn't.

Where I assign time.col to be ":0" or just ":" still does though....I'm starting to wonder if it is me, and not verge now, although the exact same code worked in v2 (save for the fact that the variable is part of a struct now.)

Posted on 2004-05-06 21:22:27

Rysen

Well, this is strange. If I take the string out of the struct, and just make it a global variable it works. o_o

Anyway, here is the broken code and maybe it'll help you figure out what's up. It's probably me and something I'm overlooking, so maybe someone can point out what I'm doing wrong.


struct TIMEVARS {
int sec, min, hour, minCount, mHour, DayTime;
string PartOfDay, timestring, col;
};

TIMEVARS time;

void clock()
{
time.sec++;
if(time.DayTime==1) { time.PartOfDay="PM"; }
if(time.min<15) { time.col = ":0"; } Else { time.col=":"; } // Crashes here
if(time.sec==40) { time.min++; time.sec=0; }
if(time.min==15) { time.MinCount=15; } // Show that 15 minutes have passed
if(time.min==30) { time.MinCount=30; } // Show that 30 minutes have passed
if(time.min==45) { time.MinCount=45; } // Show that 45 mintues have passed
if(time.min==0) { time.MinCount=0; }
if(time.Min==60) { time.Hour++; time.mHour++; time.min=0; }
if(time.hour==12 && time.sec==0 && time.min==0 && time.DayTime==1)
{
HookTimer("");
time.Daytime=0;
time.PartOfDay="AM";
time.col=":0";
time.MinCount=0;
}
if(time.hour==12 && time.sec==0 && time.min==0) { time.Daytime++; }
if(time.hour>12) { time.hour = 1; }
TimeString = str(time.hour)+time.col+str(time.MinCount)+time.PartOfDay;
}


Posted on 2004-05-06 21:50:50 (last edited on 2004-05-07 03:14:51)

el_desconocido

I put

int x = 1;
string y;
if(x) { y = ":0"; } Else { y=":"; }

in both a HookRetrace() and HookTimer(), with x = 1 and x = 0, and it does not crash.

I suspect it's actually crashing on

if(time.min==0) { time.MinCount=0; }

since I just noticed MinCount should be mCount.

The compiler seems to not really check structs well, I know for example you can have two of the same var in a struct without it whining about it.

El

Posted on 2004-05-07 01:14:55

Rysen

Ah, you got me excited for a second.

Turns out I just don't know how to type. I was typing it in by hand at first for formatting purposes but later opted to paste the code. I probably just confused mCount with mHour, so the variable is indeed MinCount I'll edit the other post to correct that.

In other words, still crashing. :(

Posted on 2004-05-07 01:31:01 (last edited on 2004-05-07 01:32:52)

el_desconocido

I got it!
Take your struct out of sytem.vc, and put it in an #include. I noticed vcc_verbose.txt showed:

struct instance declared time of type TIMEVARS (0 arraysize)

I moved it and no crash.

El

Posted on 2004-05-07 02:27:46

Rysen

Bah! I got it now too!

The struct has always been in an #include. "Time.vc"

But I thought you might be on the right track with the idea of something to do with #includes, so I moved that #include to the top of my list in system.vc (it was second and the file before it doesn't use anything from it) and now it works!

I really don't understand why it works now, because the other members of the struct worked properly, even one of the strings I had in there, PartOfDay, which was the first one I declared. It was the 2 after that, that were causing problems. Hmm...

Anyway! Thanks for the help El!

Posted on 2004-05-07 03:09:03


Displaying 1-12 of 12 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.