Jump to content
MakeWebGames

Please Demonstrate A Standard Trasaction Using NWE Variables


DungeonMaster

Recommended Posts

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.

Link to comment
Share on other sites

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 by KyleMassacre
Link to comment
Share on other sites

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.   Paste as plain text instead

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