Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help with short array script
Old 07-08-2010, 02:24 PM Need help with short array script
Junior Talker

Posts: 3
Name: Phil
Trades: 0
Hi guys/gals!

I am working on a forum signature which uses PHP-based scripts to display user statistics.

*I will describe what I have done, please be aware that I'm not completely familiar with coding/scripting terminology and so the expressions I have used are meant in their literal sense and may not be technically correct.

I have already used two array scripts to sort through the values of various user parameters and 'set' two seperate variables (one from one script, one from the other).

Code:
// Specialism Script ----------------------------------------------------------
specs.speccqbpts=p.weapons.umpk.kills;
specs.specfampts=p.weapons.m16k.kills;
specs.specsprpts=(p.weapons.m24.kills+p.weapons.svu.kills+p.weapons.sv98.kills+p.weapons.qby88.kills+p.weapons.gol.kills+p.weapons.vss.kills+p.weapons.m95.kills+p.weapons.m95k.kills);
specs.specairpts=(p.vehicles.ah64.kills+p.vehicles.ah64.roadkills);
specs.specarmpts=(p.vehicles.m1a2.kills+p.vehicles.m1a2.roadkills);
specs.specbotpts=(p.vehicles.PBLB.kills+p.vehicles.PBLB.roadkills);
spectype="None ";

speccqbtyp="Close Quarters Battle";
specfamtyp="Fire and Manoeuvre";
specsprtyp="Long Range Marksmanship";
specairtyp="Helicopter Aircrew";
specarmtyp="Armoured Vehicle Crew";
specbottyp="Boat Crew";

specvalue=0;
foreach(specs as key => val) {
  if(val>specvalue) {
    specvalue=val;
    if(key=='speccqbpts') spectype=speccqbtyp;
    if(key=='specfampts') spectype=specfamtyp;
    if(key=='specsprpts') spectype=specsprtyp;
    if(key=='specairpts') spectype=specairtyp;
    if(key=='specarmpts') spectype=specarmtyp;
    if(key=='specbotpts') spectype=specbottyp;
  }
}
spectype_color = "ffffff";

text(x: col7+10, y:line6_y-7, text: "Specialisation:", font:HeaderBld);
text(x: col7+10, y:line6_y+5, text: concat(spectype), size:10, align:"left", font:damaged, color:spectype_color);

if(spectype==specarmtyp) {image(file: "/vehicles_normal/m1a2.png", ownerid: 30788, x: col7+56, y:line4_y-39, w:180, h:45);
image(file: "/vehicles_normal/m1a2.png", ownerid: 30788, x: col7+130, y:line5_y, w:90, h:22);}
and

Code:
// Expertise Script -----------------------------------------------------------
exps.expffapts=p.gadgets.defi.revives+p.gadgets.medk.heals;
exps.expfrppts=p.gadgets.ammb.resupplies;
exps.expfrepts=p.gadgets.rept.repairs;
exps.expexppts=p.gadgets.c4.kills;
exps.expantpts=p.gadgets.rpg7.kills+p.gadgets.m2cg.kills+p.gadgets.m136.kills+p.gadgets.atm.kills;
exps.expaidpts=p.vehicles.aav.kills+p.vehicles.bmda.kills;
exps.expmfcpts=p.gadgets.mst.kills;
exptype="Recruit Skills ";

expffatyp="Field First Aid";
expfrptyp="Field Replen";
expfretyp="Field Repair";
expexptyp="Explosives";
expanttyp="Anti Tank";
expaidtyp="Air Defence";
expmfctyp="Mortar Fire Control";

expvalue=0;
foreach(exps as key => val) {
  if(val>expvalue) {
    expvalue=val;
    if(key=='expffapts') exptype=expffatyp;
    if(key=='expfrppts') exptype=expfrptyp;
    if(key=='expfrepts') exptype=expfretyp;
    if(key=='expexppts') exptype=expexptyp;
    if(key=='expantpts') exptype=expanttyp;
    if(key=='expaidpts') exptype=expaidtyp;
    if(key=='expmfcpts') exptype=expmfctyp;
  }
}
exptype_color = "ffffff";

text(x: col7+10, y:line7_y+8, text: "Expertise:", font:HeaderBld);
text(x: col7+10, y:line7_y+20, text: concat(exptype," Expert"), size:10, align:"left", font:damaged, color:exptype_color);

if(exptype==expfretyp) {image(file: "/gadgets_normal/powertool.png", ownerid: 30788, x: col7+142, y:line4_y-10, w:90, h:22);
image(file: "/gadgets_normal/powertool.png", ownerid: 30788, x: col7+130, y:line7_y, w:90, h:22);}
I now want to create a script which checks the pair of (spectype & exptype) variables resulting from the previous two scripts against a number of possible combinations and, depending on the combination of these two variables, gives a particular result (prints a message or sets a variable (plytype).

I have tried the following, which worked fine until I added more than about 10 or so 'if' statements, but now reverts to the 'else' result.

Code:
// Play Style Script ----------------------------------------------------------
plytype="G.I. Soldier DEF";

plygistyp="G.I. Soldier";
plyairtyp="Airborne";
plymartyp="Marine";
plycomtyp="Commando";
plysprtyp="Sniper";
plysabtyp="Saboteur";
plyarityp="Armoured Infantry";
plyobstyp="Observer";
plyfobtyp="Forward Observer";
plycchtyp="Crew Chief";
plycmetyp="Crew Medic";
plycmntyp="Crewman";

if((spectype==speccqbtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==specfamtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==specsprtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==speccqbtyp)&&(exptype==expmfctyp)) {plytype=plyfobtyp;}
if((spectype==specfamtyp)&&(exptype==expmfctyp)) {plytype=plyfobtyp;}
if((spectype==specarmtyp)&&(exptype==expfretyp)) {plytype=plycchtyp;}
if((spectype==specsprtyp)&&(exptype==expffatyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expfrptyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expfretyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expanttyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expaidtyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expmfctyp)) {plytype=plyobstyp;}
if((spectype==specairtyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specarmtyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specbottyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specairtyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
if((spectype==specarmtyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
if((spectype==specbottyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
else {plytype=plygistyp;}

plytype_color = "ffffff";

text(x: col7, y:line2_y, text: concat(plytype), size:12, align:"left", font:damaged, color:plytype_color);
I thought there might be a better way to do this using an array, but I don't know how to do it.

Can anyone offer any suggestions please?
Zener25 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2010, 05:28 PM Re: Need help with short array script
Extreme Talker

Posts: 246
Trades: 3
First of all, it looks like your variables are missing the dollar sign ($).

In your code, the "else" result only applies to the last "if" statement. The following should be pretty close to what you are looking for:

PHP Code:
<?php
//populate the $typeArray array with each combination of valid specialty and expertise
$typeArray = array (
    array(
$speccqbtyp,$expexptyp)=>$plysabtyp,
    array(
$specfamtyp,$expexptyp)=>$plysabtyp,
    array(
$specsprtyp,$expexptyp)=>$plysabtyp,
    array(
$speccqbtyp,$expmfctyp)=>$plyfobtyp,
    array(
$specfamtyp,$expmfctyp)=>$plyfobtyp,
    array(
$specarmtyp,$expfretyp)=>$plycchtyp,
    array(
$specsprtyp,$expffatyp)=>$plysprtyp,
    array(
$specsprtyp,$expfrptyp)=>$plysprtyp,
    array(
$specsprtyp,$expfretyp)=>$plysprtyp,
    array(
$specsprtyp,$expanttyp)=>$plysprtyp,
    array(
$specsprtyp,$expaidtyp)=>$plysprtyp,
    array(
$specsprtyp,$expmfctyp)=>$plyobstyp,
    array(
$specairtyp,$expffatyp)=>$plycmetyp,
    array(
$specarmtyp,$expffatyp)=>$plycmetyp,
    array(
$specbottyp,$expffatyp)=>$plycmetyp,
    array(
$specairtyp,$expfrptyp)=>$plycmntyp,
    array(
$specarmtyp,$expfrptyp)=>$plycmntyp,
    array(
$specbottyp,$expfrptyp)=>$plycmntyp
);

//check array for this particular specialty and expertise
if (in_array($typeArray, array($spectype$exptype))) {
    
//if it's in there, assign play type accordingly
    
$plytype=$typeArray[array($spectype$exptype)];
} else {
    
//if it's not there, it's a G.I. Soldier
    
$plytype=$plygistyp;
}
?>

Oh... I guess this was taken care of in another script.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by CouponGuy; 07-11-2010 at 05:42 PM.. Reason: I guess this was taken care of in another script.
CouponGuy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help with short array script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19297 seconds with 12 queries