I'm really newbie developing iphone apps, and I got a question...
I would like to know how must I do to receive the var that my function returns.
Take a look:
-(void)myfunc{
float num1 = 2.50;
float num2 = 3.50;
//here is my doubt, how can I get the value that function returns?
float varreceived = [self getNumber:num1:num2];
}
//the function that receive the vars and returns a value
-(float)getNumber: (float)var1 :(float)var2 {
NSLog(#"1->%f",var1);
NSLog(#"2->%f",var2);
return 3.23;
}
I receive this error when I build:
"error: void value not ignored as it ought to be"
in this line:
float varreceived = [self getNumber:num1:num2];
Update:
Nop, I receive this error when I build:
"error: void value not ignored as it ought to be"
in this line:
float varreceived = [self getNumber:num1:num2];
Max:
then you probably declared the -(float)getNumber: (float)var1 :(float)var2 as -(void)getNumber: (float)var1 :(float)var2 in your header
HispaJavi:
Yeah!! this is the problem, I wrote "-(void)getNumber" in header! I changed it "-(float)getNumber" and it works!! thanks!!
Everything is OK. You'll receive 3.23
Related
I'm developing an UEFI app using the TPM2. getCapabilities works, but everything else is shoved onto this submitCommand() function. everything I try there returns EFI_ABORTED as status.
I tried several commands, like read_PCR and get_random_number, but it appears to occur for all commands (TPM2 spec part 3). I chose the random number command because it's a simple command without authorization or encryption that should always return when executed correctly.
struct TPM2_ {
EFI_HANDLE image;
EFI_BOOT_SERVICES *BS;
EFI_TCG2_PROTOCOL *prot;
UINT32 activePCRbanks;
};
struct TPM2_Rand_Read_Command {
TPMI_ST_COMMAND_TAG tag;
UINT32 commandSize;
TPM_CC commandCode;
UINT16 bytesRequested;
};
struct TPM2_Rand_Read_Response {
TPM_ST tag;
UINT32 responseSize;
TPM_RC responseCode;
TPM2B_DIGEST randomBytes;
};
UINTN tpm_get_random(TPM2 * tpm) {
struct TPM2_Rand_Read_Command cmd;
struct TPM2_Rand_Read_Response resp;
cmd.tag = __builtin_bswap16(TPM_ST_NO_SESSIONS); //x86 is little endian, TPM2 is big-endian, use bswap to convert!)
cmd.commandCode = __builtin_bswap32(TPM_CC_GetRandom);
cmd.commandSize = __builtin_bswap32(sizeof(struct TPM2_Rand_Read_Command));
cmd.bytesRequested = __builtin_bswap16(4);
EFI_STATUS stat = tpm->prot->SubmitCommand(tpm->prot,sizeof(struct TPM2_Rand_Read_Command), (UINT8*)&cmd,sizeof(struct TPM2_Rand_Read_Response),(UINT8*)&resp); //responds 0x15 || 21
Print(L"statreadrand: %x \t %d \r\n", stat, *((UINT32*)resp.randomBytes.buffer));
CHECK_STATUS(stat, L"SubmitReadCommand");
return 0;
}
TPM2* tpm_create(EFI_BOOT_SERVICES *BS, EFI_HANDLE image) {
TPM2* tpm = calloc(1, sizeof(TPM2));
EFI_GUID prot_guid = (EFI_GUID)EFI_TCG2_PROTOCOL_GUID;
tpm->BS = BS;
tpm->image = image;
EFI_STATUS stat = tpm->BS->LocateProtocol(&prot_guid, NULL, (void **)&tpm->prot);
CHECK_STATUS(stat, L"LocateTPMProtocol");
return tpm;
}
I expect the SubmitCommand function to return EFI_SUCCESS (0) and fill the response struct with 4 random bytes. But the function returns EFI_ABORTED (21)
Does anyone know how to solve this?
EDIT: tried different toolchains (GNU-EFI/ plain GCC / EDK2) all give the same behaviour.
The particular PC had this exact problem. probably the TPM was locked.
When using a different PC With a TPM2 the problem didn' t occur and instead, I just got a random number back.
I've looked up similar questions and responses and still have not been able to get this to work.
LessonRightButton.js
//#pragma strict
public var audio1 : AudioPlayback;
function OnClick(){
var findAudioSource = GameObject.Find("AudioPlaybackButton");
var audio1:AudioPlayback = findAudioSource.GetComponent(AudioPlayback);
audio1.woo(); // THIS IS LINE 50 IN THE ERROR
}
AudioPlayback.js
//#pragma strict
function woo(){
Debug.Log("wooooooooooooooo");
}
I get this error:
NullReferenceException: Object reference not set to an instance of an
object LessonRightButton.OnClick () (at
Assets/Scripts/LessonRightButton.js:50)
I'm trying to call the woo function from a different script.
These scripts are shortened for the purpose of ease of reading. Please advise.
you have no AudioPlayback attached on that AudioPlaybackButton object.
Either add one manually or by code:
function OnClick(){
var findAudioSource = GameObject.Find("AudioPlaybackButton");
var audio1:AudioPlayback = findAudioSource.GetComponent(AudioPlayback);
if(audio1 == null){
audio1 = findAudioSource.AddComponent(AudioPlayback);
}
audio1.woo();
}
I have no idea why this code does not work. The whole idea about it is to make the value bigger until it's bigger than score.
if(score > height && rocketlaunch == false)
{
#try
{
height = [self makebigger:height];
}
#catch (NSException *exception)
{
height = height + 4000;
}
upgradeRocket.center = CGPointMake((rand()%200), -50);
rocketlaunch = true;
}
-(int)makebigger:(int)heightnr {
heightnr = heightnr + (1000 * rand() %5);
if(score > heightnr) {
[self makebigger:heightnr];
return heightnr;
} else {
return heightnr;
}
}
Does anyone know how to fix this? Or have a alternative way?
P.S.
The error displayed was:
Implicit conversion of int to id is disallowed with ARC
and
Incompatible integer to pointer conversion returning int from a function with result type id
Thank you in advance.
EDIT:
It works this way thank you very much :)
EDIT:
I got a new problem hard to solve:
this gives the error > tread 1 exc bad acces code = 2
change -makebigger:(int)heightnr to - (int)makebigger:(int)heightnr.
You have to specify the return type.
And you have to return something if the condition is true, too.
Until now I didn't even know it was possible to use no return type. But apparently it is.
Assuming score is an instance variable of type int then you have two errors in your code: first you must specify the return type of the method otherwise id is assumed; and second every path must return a value and your recursive call does not do this. Correcting those gives:
- (int)makebigger:(int)heightnr
{
heightnr = heightnr + (1000 * rand() %5);
if(score > heightnr)
return [self makebigger:heightnr];
else
return heightnr;
}
While this should work for simple value-based algorithms like this it is more usual to use iteration rather than recursion, as in:
- (int)makebigger:(int)heightnr
{
while (score > heightnr)
heightnr = heightnr + (1000 * rand() %5);
return heightnr;
}
I am going to take a guess that your "score" variable is an NSNumber. The compiler is complaining because you are trying to compare an NSNumber (object) to an int.
Try this:
if([score intValue] > heightnr)
I'm trying to create a function to calculate the mean, max, min and standard deviation of a set of numbers.
I'd like it to work like the UIColor function - (void)getRed:green:blue:alpha. i.e. you pass in the four float values and the function then overwrites them.
I'm struggling to find the right syntax for it.
My function is...
- (void)calculateStatsAverage:(float)average
standardDeviation:(float)standardDeviation
minimum:(float)minimum
maximum:(float)maximum
{
//pseudo code
average = total / count;
minimum = min value;
etc...
//
}
The problem I'm getting is getting the values out again.
If I change the function to use float* (which is what the UIColor function does) then my calculations don't like assigning the variables.
To simplify...
Imagine these functions. The first is called from elsewhere.
- (void)runThisFunction
{
float someOutputValue = 0.0;
[self changeTheValue:someOutputValue];
NSLog(#"The value is %f", someOutputValue);
}
- (void)changeTheValue:(float)value
{
value = 10.0;
}
I'd like this code to output "The value is 10.0"; But at the moment I'm getting "The value is 0.0".
Please could you show me how to write these two functions. From there I'll be able to work out the rest.
Thanks
- (void)passByRefMethod:(float *)ptr
{
*ptr = MYVALUE;
}
Sorry for formatting, typed on phone. Hope this helps!
This technique is often called pass by reference, and it's part of C so you can use that to search for more info.
Your NSLog is displaying the value of the local variable 'someOutputValue', which has been assigned to be 0.0.
Your 'changeTheValue' method has no effect.
The following code may help,
- (void)runThisFunction
{
float someOutputValue = 0.0;
float resultOfCalc = [self calcTheValue:someOutputValue];
NSLog(#"The value is %f", resultOfCalc);
}
- (float) changeTheValue:(float)value // note that this method returns a float
{
float newValue;
// do whatever calc is appropriate, e.g.
newValue = value + 10.0;
return newValue; // pass back the result of calc
}
This will output,
The value is 10.
I really have no idea how this is done, it should be simple but i just cant get it
i have an IBAction and void and want to do this:
-(IBAction)pass{
int VariableX = 10;
[self getVar]; ---> send var to -(void)getVar
}
-(void)getVar{
get the VariableX
if(VariableX=10){
do something
}
}
declare getVar function to get one (integer) parameter:
// header
-(void)getVar:(int)varX;
// implementation
-(void)getVar:(int)varX{
if (varX == 10)
// do something
}
Then call it the following way:
-(IBAction)pass{
int VariableX = 10;
[self getVar:VariableX];
}
Generally the syntax of method declaration in objective-c is:
- (ReturnType) functionName:(1st parameter type)1stParameterName
2ndParameter:(2nd parameter type)2ndParameterName
etc