473,808 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function() inputs and outputs

TheServant
1,168 Recognized Expert Top Contributor
Hey guys,
I have an untraining script in my game which I am having a small problem with. There are 4 levels of soldiers: rec, reg, exp and vet. Now the number of soldier is recorded as the total, so when a user "untrains" some, it will take it from the total. I want to remove rec's first, reg's second, etc... Now I think the function works, but I just don't know how to do inputs and outputs. I want to automatically assign the outputs to variables, let me know if this is unclear!

[php]function untrainer ( $un, $rec, $reg, $exp, $vet, &$new_rec, &$new_reg, &$new_exp, &$new_vet ) {
$new_reg = $reg; $new_exp = $exp; $new_vet = $vet;
if ( $rec >= $un ) {
$new_rec = $rec - $un ;
} else {
$new_rec = $un - $rec;
$un = $un - $rec;
if ($reg >= $un ) {
$new_reg = $reg - $un ;
} else {
$new_reg = $un - $reg;
$un = $un - $reg;
if ($exp >= $un ) {
$new_exp = $exp - $un ;
} else {
$new_exp = $un - $exp;
$un = $un - $exp;
$new_vet = $un - $vet;
}
}
}
}

untrainer ( $un, $rec_soldier, $reg_soldier, $exp_soldier, $vet_soldier, &$new_soldier_r ec, &$new_soldier_r eg, &$new_soldier_e xp, &$new_soldier_v et );
[/php]
May 16 '08 #1
7 1376
ronverdonk
4,258 Recognized Expert Specialist
I have no idea of the problem, but maybe that is because I am not a gamer.

Ronald
May 16 '08 #2
TheServant
1,168 Recognized Expert Top Contributor
I want to know how I can submit several variables to a function, and receive several variables back. Forget the game and what the function does. Just look at how I am calling the function (giving it 5 variables and receiving 4).

Thanks for your reply tho!
May 17 '08 #3
Atli
5,058 Recognized Expert Expert
That looks all right to me. If you change the values of the last four parameters in your function, the variables you assign to them when you call the function should change as well.

I assume you are attempting something like this:
Expand|Select|Wrap|Line Numbers
  1. function increment(&$value) {
  2.   $value++;
  3. }
  4.  
  5. $number = 1;
  6. increment($number);
  7. echo $number; // Should be 2
  8.  
May 17 '08 #4
dlite922
1,584 Recognized Expert Top Contributor
I have no idea of the problem, but maybe that is because I am not a gamer.

Ronald
*clueless too*


Message too short.
May 17 '08 #5
TheServant
1,168 Recognized Expert Top Contributor
OK, forget the first post. I have 4 variables $a $b $c $d that I put through a function but I want the function to update them as each of their variables:
[php]function dothis(&$a, &$b, &$c, &$d) {
$a++;
$b++;
$c++;
$d++;
}
dothis($a, $b, $c, $d);
echo($a.$b.$c.$ d);[/php]

Also do the names used in the function need to be the same as the calling? Or can it be like:
[php]function dothis(&$a, &$b, &$c, &$d) {
$a++;
$b++;
$c++;
$d++;
}
dothis($f, $g, $h, $i);
echo($f.$g.$h.$ i);[/php]
May 17 '08 #6
TheServant
1,168 Recognized Expert Top Contributor
Problem solved. My post above was correct, so thanks to everyone for replying, but a special thanks for Atli whose solution I used!
May 17 '08 #7
ronverdonk
4,258 Recognized Expert Specialist
Also do the names used in the function need to be the same as the calling? Or can it be like:
[php]function dothis(&$a, &$b, &$c, &$d) {
$a++;
$b++;
$c++;
$d++;
}
dothis($f, $g, $h, $i);
echo($f.$g.$h.$ i);[/php]
Good you solved it. As for your last question: no the names that you pass to a function are 'local' to the routine that issues the call.
The names that you declare in the function are local to the function only, so you can name them whatever you like.

Ronald
May 17 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4130
by: les_ander | last post by:
Hi, matlab has a useful function called "textread" which I am trying to reproduce in python. two inputs: filename, format (%s for string, %d for integers, etc and arbitary delimiters) variable number of outputs (to correspond to the format given as input);
4
2070
by: Mark | last post by:
Hi.. I have a c# class that i'm using to implement some extension functions and one of those functions is a simple push/pop stack. I made the c# code fairly generic, taking and returning objects - i.e public void push (object val { stack.Push (val) public object pop ( { return stack.Pop()
2
2029
by: Martin McCormick | last post by:
Most of the C programming I write manipulates strings so I haven't had much experience with numerical functions and passing variables in and out which brings me to a laughably simple problem that I am having. How does one pass two unsigned longs in to a function that will ultimately do floating point calculations on them? A C tutorial I have says that one should not declare the inputs to a function as floats but should use doubles which...
8
1543
by: darkknight | last post by:
Hi Is there any commonest practice or "industry standard" regarding comments that appear at the head of a function definition or function prototype? Do they go in the .c file only, the .h file only or both? What do the comments consist of? Pre-conditions, post-conditions, inputs, outputs, behaviour?
5
4647
by: mike | last post by:
If I have a document like: <script> function mike_test() {alert('hi');} </script> <iframe src="blank.html" id="my_iframe1"> </iframe> and in blank.html I have:
1
2226
by: enbulldog | last post by:
I am working on a program to "encrypt" a text file supplied by the user, and writing to another file also given by the user. I am very new to programming and am having trouble passing information from file to program and back to file. I am close, but I have comiler errors. Here is my code so far: #include <iostream> #include <cctype> #include <fstream> #include <iomanip> using namespace std; //Function: displayHeader
3
15651
by: Andrew Gentile | last post by:
Hello, I am trying to write a function which takes several floats as inputs, then returns 1x6 array of floats. I normally program in Matlab, and I am often confused by C. It seems that this should be an easy task, but I can't seem to get it done. Can someone please include a brief snippet of code which demonstrates how to get a function to accept 2 floats as inputs, and returns an array of 6 floats. Thanks.
2
16889
by: chobblars87 | last post by:
Hi guys. Haven't done C++ in a while and I've never been great with classes but I'm trying to make a compiler using Lex/Yacc. I've sorted most of the errors, all apart two which are both overloaded member functions that haven't been found in the class. Here's the class definition inside DetFinAut.h: #ifndef DETFINAUT_H #define DETFINAUT_H #include <iostream> #include <string>
5
3606
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at: http://www.geocities.com/usenet_daughter/javascript_radio.htm but for some reason I can only get a value if I hard code the control name.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.