试图从预定义的 p-list 中获取整数? ObjC/可可

发布于 2024-07-28 23:41:32 字数 1017 浏览 6 评论 0原文

我正在开发 Objective-C/Cocoa Roguelike,因为我一直发现开发游戏是学习语言的最佳方式。 我的游戏已经取得了很大进展,但我遇到了问题。

每个 level.plist 都定义了一些东西,如下所示:

<key>Save Location</key>
<integer>0</integer>

它是这样抓取的,我还想说这段代码工作正常:

NSObject* level = [mapDictionary_ objectForKey: kLevelNumberKey];

但是,在我的 NSLog 探索中,我我发现这不是获取一个整数,甚至是一个有用的数字,而是获取某种类型的对象,该对象在 NSLogged 时返回正确的值。 我该如何将这个值变成一个整数,以便我可以像我想要的那样使用它? 请注意,我只使用了 NSObject* 因为其他方法都无法正常工作。 如果我使用 =(int) 代替,我将获得指针值或其他值(例如 1108608)。

我确信这是一个简单的解决方案,我提前感谢您。 如果您不介意准确解释正在发生的事情,那就太好了。 我对概念的掌握很好,比大多数新人都要好,但我总是对正在发生的事情感兴趣。 如果我不知道发生了什么,那么学习编程有什么用呢! 请非常愿意向我提供其他类似情况的建议,以供我注意/做好准备。 任何建议,真的很感激,并且会提供给那些打算长期编码的人。 我把学习推迟得太久了,我唯一的遗憾是没有早点开始。

如果出于某种原因,到目前为止您有兴趣尝试我的游戏:链接我目前正在实施状态保存,以便级别保持在您离开时的水平。 显然仅限 OS X。 到目前为止,我对此感到非常自豪,但我还有很长的路要走。 应用程序中列出了控件。

I'm working on an Objective-C/Cocoa roguelike, because I've always found that working on a game is the best way to learn about a language. I've gotten quite far with my game, but I'm having a problem.

Each level.plist is defined with a few things, like so:

<key>Save Location</key>
<integer>0</integer>

It's grabbed like so, I'd also like to say that this code is all working fine:

NSObject* level = [mapDictionary_ objectForKey: kLevelNumberKey];

However, in my NSLog-exploring, I've found that instead of grabbing me an integer, or even a useful number, this grabs me an object of some sort, which returns the correct value when NSLogged. How would I go about making this value into an integer so that I can use it like I'd want to be? Note that I've only used NSObject* because nothing else worked right. If I used =(int) instead I would get the pointer value or whatever (1108608 for example).

I'm sure it's a simple solution, and I thank you in advance. If you would not mind explaining exactly what is happening, that would be great. My grasp of the concepts is fine, better than most newcomers, but I'm always interested in exactly what is happening. What use would learning to program be if I didn't know what was going on! Please be more than willing to advise me of other situations like this to watch out/be ready for as well. Any advice, really is appreciated, and will be going to somebody who intends to code for a very long time. I put off learning this much too long, my only regret is not starting earlier.

If, for whatever reason, you are interested in trying out my game so far: Link I'm currently in the process of implementing state-saving so that levels remain as you left them. It's obviously OS X only. I'm pretty proud of it so far, but I have a long ways left. The controls are listed in the app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文