- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用Bricx Command Center为Lego Mindstorms NXT block 编写一个简单的十五个谜题。但总是有同样的问题。数组的元素(无论维度)第二次不会改变。
这是模拟错误的代码。如果您没有 NXC block 来检查它,程序会输出 4x4 的零网格(并且没问题),然后程序退出并显示“文件错误!”在 LCD 屏幕上,大概是在尝试将数组的第一个零元素更改为 1 时。
如果您有任何想法,请告诉我。我认为 NXC 语言并不是为了以这种特定方式处理数组而开发的,尽管我觉得它很奇怪......
附注我还尝试使用内置函数 ArrayReplace() 但没有成功。
这是代码示例:
int count;
int numMatrix[] = {1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 69};
const int xcoord[] = {12, 37, 62, 87};
const int ycoord[] = {56, 40, 24, 8};
void fillGrid(){
int j, k;
for (int i = 0; i < 16; i++){
numMatrix[i] = count;
if (k == 4){
k = 0;
j++;
}
NumOut(xcoord[j], ycoord[k], numMatrix[i]);
Wait(50);
k++;
}
Wait(2000);
ClearScreen();
}
task main(){
while (true){
fillGrid();
count++;
}
}
好吧,这显然是我的错,我应该初始化 j 和 k 局部变量并将它们等于 0。现在看看我尝试对二维数组执行相同操作的情况。
#define NROWS 4
#define NCOLUMNS 4
int count;
int numMatrix[NROWS][NCOLUMNS] = {
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 69} };
const int xcoord[] = {12, 37, 62, 87};
const int ycoord[] = {56, 40, 24, 8};
void fillGrid(){
for (int i = 0; i < NROWS; i++){
for (int j = 0; j < NCOLUMNS; j++){
numMatrix[j][i] = count;
NumOut(xcoord[i], ycoord[j], numMatrix[j][i]);
Wait(50);
}
}
Wait(2000);
ClearScreen();
}
task main(){
while (true){
fillGrid();
count++;
}
}
任何事情都不会改变,数组的所有元素将保持与初始化时相同(1、2、3...)。现在变得更有趣了..
最佳答案
问题是:在 C 中,局部变量在堆栈上分配,并且默认情况下不会为您初始化,您必须自己执行此操作。
int count; // global: automatically initialized to zero
void fillGrid() {
int j = 0, k = 0; // local: NOT automatically initialize - you do it.
for (int i = 0; i < 16; i++){
numMatrix[i] = count;
if (k == 4){
k = 0;
j++;
}
NumOut(xcoord[j], ycoord[k], numMatrix[i]);
Wait(50);
k++;
}
...
}
如果您没有初始化它们,无论堆栈上有什么,您都会得到随机垃圾:在我的系统上,j
确实为零,但 k
是4195392。
I presume that NXC language wasn't developed to work with arrays in that particular way
这实际上与它没有任何关系:库代码(例如,NumOut
)永远不会看到数组,只能看到从数组索引并单独传递给图书馆。
关于c - 乐高头脑 Storm NXT、NXC : Error in replacing elements in an array (no matter the dimension),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59439923/
Matter-js - 如何获得矩形的宽度和高度? 我需要知道是否在 Matter-js 中实现了距离返回方法。 // part.vertices[0] and part.vertices[1] 我想
如何在 Matter.js 中添加以编程方式触发的触摸/鼠标事件?我为引擎设置了一些碰撞事件,但无法触发停止当前拖动操作的 mouseup 事件。我已经尝试了针对 canvas 元素、mouse/mo
我正在使用matter.js我有具有绝对位置的对象的顶点数据(来自 SVG 文件)。当我尝试将它们放置在 map 上时,它们最终都位于 0, 0 附近。通过以下代码片段可以轻松观察到这一点:
我经常读如下语句: “当变量将被多个线程读取和写入时,请使用“同步”。 来源: https://jorosjavajams.wordpress.com/volatile-vs-synchronized
是否可以在matter.js中创建位于x/y坐标中心的单个重力/力点? 我已经成功地使用 d3.js 做到了这一点,但想询问 Matter.js,因为它能够使用多个 Polyshape。 http:/
授予,micro-optimization is stupid并且可能是实践中许多错误的原因。尽管如此,我还是看到很多人这样做: void function( const double& x ) {}
我当前的实现使用大量具有这种语法的复制构造函数 MyClass::Myclass(Myclass* my_class) 它真的(功能上)不同于 MyClass::MyClass(const MyCla
原始问题: JSHint当我的 JavaScript 调用一个定义在页面下方的函数而不是对它的调用时,就会提示。但是,我的页面是用于游戏的,在整个下载完成之前不会调用任何函数。那么为什么出现在我的代码
我有一个 Hugo 网站,每个文件都有翻译,使用页面包。 所以关于页面看起来像这样: - about - about-image.jpg - index.en.md - index.nl.
我正在尝试运行一个在服务器上运行物理模拟的服务器,并让客户端通过 websockets/socket.io 连接到该服务器。我知道我可以使用 Matter.js 将引擎与渲染分开计算。所以我的问题是,
我通过 Matter.js 创建了如下两个矩形 我正在尝试将“a”框移到“b”框上方。 我想我应该写applyForce此时,如何计算适当的 X、Y 力值以放入因子? 下面的代码是由粗略的近似值组成的
WHERE IN 子句中值的顺序是否重要? (如果这很重要,这是在 Firebird SQL 上) 比如: where field1 in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10
一切都是不变的,但是将 chrome 选项卡移动到另一个监视器会以某种方式影响落球的物理特性 问题视频:(在mac上录制) https://www.youtube.com/watch?v=eNoVsh
问题.js - 这是 one of the demo来自matter.js。它返回一个空白屏幕。我尝试了几种方法,并在这方面花费了数小时和数小时,但仍然无法弄清楚这里出了什么问题。 我检查了括号、语法
我正在尝试以编程方式设置 matter.js 中链接主体的宽度和高度。不幸的是,我只得到 0 作为值,我不确定为什么。我的猜测是图像加载速度不够快,无法提供这些值。如何在加载图像之前加载这些尺寸? 伪
我对在这里提问还比较陌生,所以请多多包涵。我正在尝试使用 Matter.js 作为主要物理引擎创建一个自上而下的驾驶游戏。我希望红色汽车与绿色广场相撞。然而,我仍然不知道如何在我的游戏中实现 Matt
我使用不同的语言和平台从事各种项目。我将其中的一部分抽象到他们自己的独立项目中,我想向公众开放其中的一些。 让我卡住的是洗礼。 那么,有关系吗?我应该选择一些东西并坚持下去吗? 如果它确实重要,那么更
下面是在执行时引发一些错误的代码。我想做的是无论什么(错误或无错误)都将执行代码的最后一行。 "backend_photo_album", )); @unlink($file_path);
我正在使用 .js 创建一个简单的游戏,您必须将球插入洞中。 如果我使用 isStatic: false对于球对象,在游戏开始时它会掉落。如何旋转整个平台,使其保持水平并且物体不会掉落但可以被插入?
我正在创建一个项目,其中用户拾取并抛出一个物体(使用鼠标约束)。 body 被设置为可以绕约束点枢转。我需要找出,从放开它的那一刻起,它在着陆之前完全旋转了多少次(+-360 度)。阅读文档,我能找到
我是一名优秀的程序员,十分优秀!