Jump to content

Noob help


MetalSmith

Recommended Posts

I can't get my script to see this chunk of code. It just overlooks the function. Why? All it is supposed to do is this (119+$y) which is this (119+12)

 

function center_total($x)

{

  if ($x > 999)

  {

  $y = 12;

  }

}

 

center_total(1000);

 

imagestring($image, 3, (119+$y), ((1210-(($total_calls/500)*50))-15), "$total_calls", $black);

Link to comment
Share on other sites

So do you know why mine didn't work? I have a problem understanding how custom functions work.

 

Thanks for all the help!

 

 

Look into variable scope.

 

 

$x inside a function is not the same as $x outside of a function (unless $x is passed by reference).

 

 

 

 

Exiting it can make it so it will stop reading it. I'm saying, it's an exit tag issue occasionally.  >:(

 

 

Huh?

Link to comment
Share on other sites

The exit(); function stops the reading, and the error process of some scripts. It's likely not the issue, but it is common to some scripts, and it may have been the issue, most likely not.

 

Variables are good to work with,

 

$xy_total = "$center_total"($x)

{

  if ($x > 999);

  $y = 12;

}

 

center_total(1000);

 

imagestring($image, 3, (119+$y), ((1210-(($total_calls/560)*50))-15), "$total_calls", $black);

 

Goodluck!  ;):D

Link to comment
Share on other sites

what on earth is this?

 

$xy_total = "$center_total"($x)
{
  if ($x > 999);
  $y = 12;
}

center_total(1000);

imagestring($image, 3, (119+$y), ((1210-(($total_calls/560)*50))-15), "$total_calls", $black);

 

first, variables are kinda good to work with in the sense that they are kinda a little important to coding. secondly, that is the most bastardized piece of code i've ever seen.

Link to comment
Share on other sites

Why don't you stop criticizing me? How do I know what you're talking about? You've proposed no intelligent hints as where to go.

 

That code is actually working on my side, maybe you should read that topic before you start giving advice.  :P

Link to comment
Share on other sites

Corbin do you mean $y and not $x? $x is what ever I make it but $y is a specific value.

 

He is just saying, that a variable in a function is confined to within that function.

 

so if you have

 

$x=1;

 

function ok(){

$x=2;

}

 

then $x will be 1 outside the funciton and 2 inside. it wont overwrite it. the variables are in seperate scopes.

 

check it out here.

Link to comment
Share on other sites

So do you know why mine didn't work? I have a problem understanding how custom functions work.

 

Thanks for all the help!

 

In your code $y isn't defined as anything. Function variables are independant from the rest of the scripts variables.

 

Like


function pug(){
$pug = pug;
return $pug;
}

pug();

echo $pug; /// This will come out as blank.

 

But if I define the variable $pug as the result of the function such as:

 

 



function pug(){
$pug = pug;
return $pug;
}

$pug = pug();

echo $pug; /// This will come out as pug.

 

 

So do as seventheyejosh said. Instead of centertotal(1000); being alone, do $y = centertotal(1000);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.