0

当我尝试在 xcode 模拟器中测试我的游戏时,我在下面收到这些错误。任何人都知道出了什么问题。顺便说一句,如果演员与物体碰撞,则行为是解锁新关卡:

第 49 行错误:“objc_object*”和“float”类型的无效操作数转为二进制

第 58 行错误:“objc_object*”和“float”类型的无效操作数转为二进制

第 73 行错误:iso c++ 禁止指针和整数之间的比较

这是 IOS 代码: 第 49 行:

 if(([mActor touchedActor] && ([self getGameAttribute:@"Highest Level Completed"] >= [self asNumber:[NSNumber numberWithFloat:_levelnumber]])))

第 58 行:

if(([self getGameAttribute:@"Highest Level Completed"] >= [self asNumber:[NSNumber numberWithFloat:_levelnumber]]))

第 73 行:

 if(([mActor touchedActor] && (([self getGameAttribute:@"Highest Level Completed"] <= 5) && [[Game game] purchasedProduct:@"MyID"])))

该行为的所有代码:

#import <Box2D/Box2D.h>
#import <AudioToolbox/AudioServices.h>
#import <Foundation/Foundation.h>
#import "ActorScript.h"

#import "Script.h"

#import "Actor.h"
#import "ActorType.h"
#import "Assets.h"
#import "Behavior.h"
#import "Collision.h"
#import "CollisionPoint.h"
#import "Game.h"
#import "GameModel.h"
#import "GroupDef.h"
#import "FadeInTransition.h"
#import "FadeOutTransition.h"
#import "Region.h"
#import "Runnable.h"
#import "Scene.h"
#import "SHThumbstick.h"
#import "Sparrow.h"
#import "Transition.h"



@interface Design_190_190_Clicktoplaylevel : ActorScript 
{
    @public
        NSString* tempHolder;

Scene* _Scenetoplay;

NSString* _Levellabel;

float _levelnumber;

}
@end

@implementation Design_190_190_Clicktoplaylevel

-(void)load
{
        [self addWhenUpdatedListener:nil func:^(NSMutableArray* list, Script* theScript){
Design_190_190_Clicktoplaylevel* self = (Design_190_190_Clicktoplaylevel*) theScript;

                    if(([mActor touchedActor] && ([self getGameAttribute:[self asNumber:[NSNumber numberWithFloat:[[self getGameAttribute:@"Highest Level Completed"] floatValue]]]] >= [self asNumber:[NSNumber numberWithFloat:_levelnumber]])))
{
                [self setGameAttribute:[[self getGameAttribute:@"Current Level"] floatValue] value:[NSNumber numberWithFloat:[self asNumber:[NSNumber numberWithFloat:_levelnumber]]]];
                [self switchScene:_Scenetoplay.ID leave:[self createFadeOut:((1000*1)) color:0] enter:[self createFadeIn:((1000*1)) color:0]];
}

}];
    [self addWhenDrawingListener:nil func:^(SPRenderSupport* g, int x, int y, BOOL screen, NSMutableArray* list, Script* theScript){
Design_190_190_Clicktoplaylevel* self = (Design_190_190_Clicktoplaylevel*) theScript;
        if(([self getGameAttribute:[self asNumber:[NSNumber numberWithFloat:[[self getGameAttribute:@"Highest Level Completed"] floatValue]]]] >= [self asNumber:[NSNumber numberWithFloat:_levelnumber]]))
{
            [mActor setAnimation:@"Animation 1"];
            [[Game game] setFont:[ self getFont:52] size:1];
            [[Game game] drawString:_Levellabel x:(([mActor getWidth] - [[Game game] getWidthForString:[ self getFont:52] string:_Levellabel]) / 2) y:30];
}

        else
{
            [mActor setAnimation:@"Animation 0"];
}

}];
    [self addWhenUpdatedListener:nil func:^(NSMutableArray* list, Script* theScript){
Design_190_190_Clicktoplaylevel* self = (Design_190_190_Clicktoplaylevel*) theScript;
                    if(([mActor touchedActor] && (([self getGameAttribute:[self asNumber:[NSNumber numberWithFloat:[[self getGameAttribute:@"Highest Level Completed"] floatValue]]]] <= [self asNumber:[NSNumber numberWithFloat:5]]) && [[Game game] purchasedProduct:@"MyID"])))
{
                [self setGameAttribute:[[self getGameAttribute:@"Current Level"] floatValue] value:[NSNumber numberWithFloat:[self asNumber:[NSNumber numberWithFloat:_levelnumber]]]];
                [self switchScene:_Scenetoplay.ID leave:[self createFadeOut:((1000*1)) color:0] enter:[self createFadeIn:((1000*1)) color:0]];
}

            else if((([mActor touchedActor] && [self sameAs:[self getGameAttribute:[self asNumber:[NSNumber numberWithFloat:[[self getGameAttribute:@"Highest Level Completed"] floatValue]]]] two:[NSNumber numberWithFloat:[self asNumber:[NSNumber numberWithFloat:5]]]]) && !([[Game game] purchasedProduct:@"MyID"])))
{
                return;
}


}];

} 




-(void)forwardMessage:(NSString*)msg
{
4

1 回答 1

0

看起来在所有三种情况下问题都是相同的 - 您正在尝试比较NSNumber对象。比较运算符(<=&>=在您的情况下)不会重载到 accept NSNumber

NSNumber本身有三个方法:isEqualToNumber:, isEqual:, 和compare:; 这将比较两个NSNumber实例。

您还可以比较NSNumberusing floatValue, inValue, et al的值。因此,例如,您的最后一个比较可能是:

[self getGameAttribute:@"Highest Level Completed"].intValue <= 5

或使用方法,而不是属性,语法:

[[self getGameAttribute:@"Highest Level Completed"] intValue] <= 5

顺便说一句,您似乎将游戏关卡存储为浮点数。我显然不了解您的应用程序,但将其存储为整数似乎更合乎逻辑,并且避免了浮点舍入问题(取决于您对它们执行的操作)。

于 2013-05-26T19:44:05.027 回答