DungeonMaster Posted June 15, 2013 Posted June 15, 2013 To avoid using typical PHP I will please like to see an example the NWE way to do the following : Use a simple form and field to buy an orange and add it to the user's variable. On a page you have $orange = GetUserVariable(orange); $cost = 2; At present $orange = 0 now I need a simple form that enables me to input the number of oranges to buy at $cost and then do 2 things: 1. Add the number to $orange 2. Subtract the amount from currency Thanks in advance. Quote
KyleMassacre Posted June 15, 2013 Posted June 15, 2013 (edited) ill have a go if(isset($_POST["orangeQty"]) + 0) { //To make things easier on the eyes I will just make things its own variable //For get user var @param1 is a constant which is the user variable name, @param2= A useridn if null it returns $userId by default $oranges = GetUserVariable(orange); //Just for the beck of it I will demonstrate the config value, @param1=value name @param2=module name $cost = GetConfigValue("orangeCost","thisModule"); //This is just to make the deduction of money easier $updateCurrency = $_POST["orangeQty"] * $cost; //See how much easier that is $userStats["!Currency"]->value -= $updateCurrency; //Now lets give the player his new orange amount. @param1 is a constant for the user variable name, @param2 will be what you are going to set param1 to, and param3 is just the same and get user variable param2 which is a userid for the user you are working with SetUserVariable(orange,$oranges+$_POST["orangeQty"]); } TableHeader("We are going to buy some Oranges"); echo "<table>"; echo "<form method='post' name='buyOrange"'>"; echo "<tr><td><b>How Many Oranges?:</b></td>"; echo "<td><input type ='text' name = 'orangeQty' value = '1' /></td></tr>"; echo "</form>"; echo "</table>"; TableFooter(); ButtonArea(); SubmitButton("Buy Orange","buyOrange"); EndButtonArea(); Pretty simple huh? Good luck ;) Edited June 16, 2013 by KyleMassacre Quote
DungeonMaster Posted June 16, 2013 Author Posted June 16, 2013 Thank you very much Kyle. I will fit this in with my code and see how it works. Quote
KyleMassacre Posted June 16, 2013 Posted June 16, 2013 Anytime. Maybe on my blog I don't use I can set up some random stuff with NWE in there like little tuts or something Quote
DungeonMaster Posted June 16, 2013 Author Posted June 16, 2013 You are very helpful, thank you so much. I made some adjustment and that works for me well. I will be sure to open threads when I need further explanation as the Wiki is very sparse. Quote
KyleMassacre Posted June 16, 2013 Posted June 16, 2013 Yeah it took me a minute to figure out how to dial in the user variables. But please do post if you have any questions ill do my best to help when I can Quote
a_bertrand Posted June 16, 2013 Posted June 16, 2013 BTW You could either use a uservariable or a stat. The stat could be a bit easier to work with and would have the advantage to be loaded all the time for you. All depends what you do with such "oranges" ;) Quote
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.