vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Functions :) (https://vborg.vbsupport.ru/showthread.php?t=122949)

pyro.699 08-03-2006 10:05 PM

Functions :)
 
Ok, i will try and make this as simple as i can.

I am making a script that is somewhat like diablo 2, where you have an inventory, and a dropdown menu with item stats and other things. Like in diablo 2, there are requirements and you need to achieve that score before you can equip that item. I have a quick function to get the requirements and spit them out.

PHP Code:

function requirements($itemid$userid)
{
    global 
$db$itemTypes;
    
$req $db->query_first("SELECT * FROM `abp_items` WHERE `id` = '$itemid'");
    if(
$userid != 0)
    {
        
$usr $db->query_first("SELECT * FROM `user` WHERE `userid` = '$userid'");
    }
    
$equip TRUE;
    if(
$req['req_lvl'] != and $usr['level'] >= $req['req_lvl'])
    {
        
$requiremnt .= '
        <div width="50%" style="background-color: #CCFFCC">
            Required Level: '
.$req['req_lvl'].'
        </div>'
;
    
    }
    elseif(
$req['req_lvl'] != and $usr['level'] < $req['req_lvl'])
    {
        
$requiremnt .= '
        <div width="50%" style="background-color: #FFCCCC">
            Required Level: '
.$req['req_lvl'].'
        </div>'
;
        
$equip FALSE;
    }
.....

    return 
$requiremnt;
    return 
$equip;


I run this function in 1 place, but it will be soon be 2. How do i get $equip, without getting $requirement?

PHP Code:

$var '<div id="item'.$total.'_menu" style="width: 25%; height: auto; display:none; padding: 4px; border-style: dotted; border-width: 1px;" class="alt2"> 
            <div style="width: 75%">
                '
.$description.'
            </div>
            <hr width="40%">
            '
.requirements($id$userid).'
            <hr width="40%">
            '
.attributes($id).'
        </div>'


In the function you see $equip, when it is set to true, there is a link that enables you to equip the item. If it is set to false there is no link beacuse they have not met the requirements.

How do i make it so that i can go

PHP Code:

requirements($id$userid)
if(
$equip == true)
{
    echo 
'<a href="#equip....">You can equip this item</a>';


$equip should be set? right, or do i need to use global?

Thankyou
~Cody Woolaver

pyro.699 08-06-2006 11:47 AM

Im guessing that i dont need to use 'return' is there some other value that i should be using?

Paul M 08-06-2006 12:02 PM

Store $requirement and $equip in an array and then return the array ;

PHP Code:

$ret = array();
$ret['equip'] = $equip
$ret['requirement'] = $requirement
return 
$ret 

Then you can do this ;

PHP Code:

$req requirements($id$userid);
if(
$req['equip'] == true)
{
    echo 
'<a href="#equip....">You can equip this item</a>';


(it would be better to store them in the array all through original function code, rather than just assign them at the end)

pyro.699 08-06-2006 12:38 PM

ah, thanks a ton paul :)


All times are GMT. The time now is 09:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01151 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete