Jump to content

[SOLVED] Really weird function problem...


BioRiot

Recommended Posts

I've been using this function in many places in 15,000+ lines of code, and it has NEVER done this. I've tested line by line and changed these values and value names a ton of times...but I'm totally stumped on this one. (I know newtxtLine() is a crappy function and I should probably use an associative table instead, but I really just want to know whats causing this problem)

 

Here are snippets of the code that is giving me problems:

(below the code I explain the actual problem)

 

function giveFight($fid, $givewhat, $value){
include '/home/chuck/configSGame.phps';
include '/home/chuck/opendb.phps';
$result2 = mysql_query("UPDATE fight SET $givewhat = '$value' WHERE fid = $fid");
}


function newtxtLine($fid, $newtxt){
include '/home/chuck/configSGame.phps';
include '/home/chuck/opendb.phps';
giveFight($fid, txt10, getFight($fid, txt9));
giveFight($fid, txt9, getFight($fid, txt8));
giveFight($fid, txt8, getFight($fid, txt7));
giveFight($fid, txt7, getFight($fid, txt6));
giveFight($fid, txt6, getFight($fid, txt5));
giveFight($fid, txt5, getFight($fid, txt4));
giveFight($fid, txt4, getFight($fid, txt3));
giveFight($fid, txt3, getFight($fid, txt2));
giveFight($fid, txt2, getFight($fid, txt1));
giveFight($fid, txt1, $newtxt);
}

 

 

and then in another function, i have this code, which is malfunctioning:

 

$mobname = getMob($fighterid[$fornum], mobname);
$newtxt2 = "$mobname has died!";
newtxtLine($fid, $newtxt2);

 

and further down:

 

$playername = $namesforgains[0];
$newmsg = "$playername has gained $exp Experience, $credits Credits, and 1 Morale.";
newtxtLine($fid, $newmsg);

 

 

Okay now the problem...and i SWEAR TO YOU, its THESE lines doing it, because I've commented out all the other lines in my code...and its not from a loop or anything...both values ($newtxt2, and $newmsg) write to the database as "$mobname has died!" instead of the seperate strings.

 

I've even commented out the second newtxtLine() statement, and when I do that, it only writes "$mobname has died" once.

 

I've tried everything I can think of.. in case the function was somehow retaining the value I had it set $newtxt = ""; afterward...it still wrote both times as "$mobname has died". I am...completely at a loss here. Anyone have any suggestions?

 

Thanks in advance,

 

Chuck

Link to comment
https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/
Share on other sites

Make sure you're echoing out these values before/after you pass them in the function and in each function to make sure they contain the values they're supposed to.  There's probably a mix up somewhere where you're assigning two variables the same value.

 

NOTE - Please use


around code for proper formatting and syntax highlighting.

Sorry this is my first post here, I modified it to show the code properly.

 

Yes I echoed out each line, and commented out each line.

 

$newtxt2 echoed out as "Space Critter has died!";

and

$newmsg echoed out as "Chuck has gained 1 Experience, 5 Credits, and 1 Morale.";

 

...and there are no lines in between those when tested. Same issue. As I said, it makes no sense to me whatsoever.

 

Hey Ken,

 

Just tried that out, same deal. Two in a row. I'm considering changing the whole thing over to an associative table but if I still have this same issue I'm going to flip cos there's no reason this shouldn't work  :( and I'm not sure if changing it over will even help. I commented out all lines except those, and changed the values to just names, and I'm having the same problem. My only guess is it has something to do with the 2 functions, but I can't figure it out.

For some reason, these 4 lines aren't working. If i comment out line 2, NOTHING gets written to the database...not even for the 2nd newtxtLine(). If I comment out line 4, only 1 copy of $mobname has died is written to the database.

On its own, both instances of newtxtLine() are writing "$mobname has died"

 

$newtxt2 = $mobname. " has died!";
newtxtLine($fid, $newtxt2);
$newmsg = "$playername has gained '$exp' Experience, '$credits' Credits, and 1 Morale.";
newtxtLine($fid, $newmsg);

Well...I changed everything to associative tables instead...still had the same problem. So, I went back, took out the ' ' in

$newmsg = "$playername has gained '$exp' Experience, '$credits' Credits, and 1 Morale.";

 

which I had added before...because I had the problem before I put those in there, and now it works properly. I have no idea what all that was about, but thanks for your help guys.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.