Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XCODE从文件中读取文本会删除变量_Xcode_File_Sprite Kit_Text Files - Fatal编程技术网

XCODE从文件中读取文本会删除变量

XCODE从文件中读取文本会删除变量,xcode,file,sprite-kit,text-files,Xcode,File,Sprite Kit,Text Files,这可能是我见过的最奇怪的错误。 我正在创建一个迷宫游戏,从文本文件加载关卡,但如果文件有三行以上,它似乎会随机更改我的大多数变量。我加载一个文本文件,然后遍历这些行,并根据其字母在适当的位置创建一个对象。 有什么建议吗 文本文件: TTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTT TTTTT RPPGPPDTTTTT ttttptptttt TTTTPPPWPPTTTTT ttttptppptttt ttttppptptttt

这可能是我见过的最奇怪的错误。 我正在创建一个迷宫游戏,从文本文件加载关卡,但如果文件有三行以上,它似乎会随机更改我的大多数变量。我加载一个文本文件,然后遍历这些行,并根据其字母在适当的位置创建一个对象。 有什么建议吗

文本文件: TTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTT TTTTT RPPGPPDTTTTT ttttptptttt TTTTPPPWPPTTTTT ttttptppptttt ttttppptptttt ttttptppptttt ttttt upppplttt TTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTT

NSString *path = [[NSBundle mainBundle] pathForResource:@"map2c" ofType:@"txt"];
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil];
NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\r\n"]];
int y  = 0;
for (NSString* line in lines) {

    NSString* ty = @"TBGWUDLRP";
    char *str = (char *)[line UTF8String];
    char *str2 = (char*)[ty UTF8String];
    grannyMoving = 2;
    int x = str2[0];
    char x2 = str2[1];
    char GrannyStr = str2[2];
    char wolfStr = str2[3];

    char UpStr = str2[4];
    char DownStr = str2[5];
    char leftStr = str2[6];
    char rightStr = str2[7];
    char PathStr = str2[8];
    y--;
    maxY = y;
    if (line.length) {
        maxI = line.length;
        for (int i = 0; i< line.length; i++) {                
 SKSpriteNode* tree = [SKSpriteNode spriteNodeWithImageNamed:@"tree3"];
            tree.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(31, 31)];
            tree.physicsBody.affectedByGravity = false;
            tree.physicsBody.dynamic = NO;
            tree.position = CGPointMake(64*i+20, 64*y+800);
            tree.zPosition = -1* tree.position.y;
从:

此C字符串是指向string对象内部结构的指针, 它的生存期可能比字符串对象短,并且将 当然不会有更长的寿命。因此,您应该复制C 字符串,如果它需要存储在 您可以使用此属性


要解决此问题,必须复制UTF8String返回的字符。提供两种解决方案。

重置的变量不仅仅是这些变量,甚至是在此之前设置的属性,包括SKActionsASO获取我分配的变量的exc\u bad\u访问权限