nindall 0 Posted April 6, 2006 As a part of some scripting involving trigonometry I wanted to write what I thought would a simple function to convert a negative number into a positive or vice-versa. PosNeg.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_n"]; _n = _this select 0; _n = (_n - (_n * 2)) From a dialog text-box (If that makes any difference) I preprocessed and then tried to call it using - <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> hint format ["%1",[37] Call PosNeg] It dosn't return any errors but prints '<null>'. I also tried putting brackets around the '[37] Call PosNeg'. Thanks in advance. Share this post Link to post Share on other sites
nindall 0 Posted April 7, 2006 Solved! By adding another line containing the result - PosNeg.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_n"]; _n = _this select 0; _n = (_n - (_n * 2)); _n Can anyone clarify why this is necessary? I thought functions could end with an assignment? Share this post Link to post Share on other sites
benreeper 0 Posted April 9, 2006 I guess you have to return just the var. All operations, including the last assignment require a semi-colon. --Ben Share this post Link to post Share on other sites
UNN 0 Posted April 9, 2006 Quote[/b] ]I thought functions could end with an assignment? They can, but it would have to be written like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_n"]; _n = _this select 0; (_n - (_n * 2)) Share this post Link to post Share on other sites
baddo 0 Posted April 9, 2006 Let's shorten it a bit: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_this - (_this * 2) Then call it without the brackets around the number: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format ["%1",37 Call PosNeg] Explanation: you already have _this variable holding the number, no need for another variable _n. Share this post Link to post Share on other sites