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); 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); 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 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!? 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. 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! 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? 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. 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! 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. 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. 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. 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? 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. 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); 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! 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 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 Link to comment https://forums.phpfreaks.com/topic/165430-noob-help/#findComment-872541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.