MetalSmith Posted July 10, 2009 Share Posted July 10, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/ Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 try function center_total($x){ if ($x > 999) { $y = 12; }else{$y=''} return $y; } $y=center_total(1000); Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872505 Share on other sites More sharing options...
The Eagle Posted July 10, 2009 Share Posted July 10, 2009 This is a common issue for mostly ALL scripts in PHP. Firstly, try the method provided by josh above. If that doesn't resolve it, add exit(); to the end (before <?) G'Luck! :o :o Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872510 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 This is a common issue for mostly ALL scripts in PHP. Firstly, try the method provided by josh above. If that doesn't resolve it, add exit(); to the end (before <?) G'Luck! :o :o what on earth are you talking about!? Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872511 Share on other sites More sharing options...
The Eagle Posted July 10, 2009 Share Posted July 10, 2009 Exiting it can make it so it will stop reading it. I'm saying, it's an exit tag issue occasionally. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872514 Share on other sites More sharing options...
MetalSmith Posted July 10, 2009 Author Share Posted July 10, 2009 So do you know why mine didn't work? I have a problem understanding how custom functions work. Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872517 Share on other sites More sharing options...
corbin Posted July 10, 2009 Share Posted July 10, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872521 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 exiting wont magically make a function return a value, let alone store that value into a variable. ever. I don't believe you even know what you're talking about. I'd go here before i start giving out advice, the eagle. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872522 Share on other sites More sharing options...
The Eagle Posted July 10, 2009 Share Posted July 10, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872525 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872527 Share on other sites More sharing options...
MetalSmith Posted July 10, 2009 Author Share Posted July 10, 2009 Corbin do you mean $y and not $x? $x is what ever I make it but $y is a specific value. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872528 Share on other sites More sharing options...
The Eagle Posted July 10, 2009 Share Posted July 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872530 Share on other sites More sharing options...
MetalSmith Posted July 10, 2009 Author Share Posted July 10, 2009 ehehe thats awesome my post started a fight but can you all answer my last post? Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872531 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872532 Share on other sites More sharing options...
PugJr Posted July 10, 2009 Share Posted July 10, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872533 Share on other sites More sharing options...
MetalSmith Posted July 10, 2009 Author Share Posted July 10, 2009 Great thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872535 Share on other sites More sharing options...
joel24 Posted July 10, 2009 Share Posted July 10, 2009 It's likely not the issue, but it is common to some scripts, and it may have been the issue, most likely not. hahaha Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872537 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 Quote from: The Eagle on Today at 10:26:37 PM It's likely not the issue, but it is common to some scripts, and it may have been the issue, most likely not. hahaha i couldn't agree more Quote Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.