小编use*_*657的帖子

在inform 7中,为什么这个复杂的语句不能作为文本替换?

这是一个代码片段,用于显示我目前在源代码中的内容:

A morph is a kind of thing.
A morph has some text called animal name.
A serum is a kind of thing.

Revelation relates one serum to one morph.  The verb to reveal (he reveals, he revealed, it
  is revealed, he is revealing) implies the revelation relation.
Run Code Online (Sandbox Code Playgroud)

在我的游戏中,我想要喝一种血清,让玩家转变为特定的动物.该动物的名称存储为名为"动物名称"的文本属性.我希望能够仅仅根据血清本身来引用这个名称,所以我添加了变形和血清对象之间的关系.

然后我添加这个规则:

Instead of drinking a serum:
    say "You can now become a [animal name of
     morph revealed by noun].";
    now the morph revealed by the noun is held by the player; …
Run Code Online (Sandbox Code Playgroud)

inform7

6
推荐指数
1
解决办法
167
查看次数

更改innerHTML只能工作一次

我正在尝试用HTML制作记分牌,其中javascript函数可以改变各种玩家的分数.但是,除了其中一个玩家之外的所有玩家的分数都无法正确显示.

HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
</head>
<body>
    <div id="scoreboard"></div>
    <script type="text/javascript" src="main.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

function Player(ID) {
    this.ID = ID;

    var scoreboard = document.getElementById("scoreboard");

    //Create a <p> in scoreboard with "Player n:" in it, and then
    //create a <span> with the score and a unique ID to use for getting and setting
    scoreboard.innerHTML += "<p>Player " + this.ID + ":" + "<span id=\"PlayerScore" + this.ID + "\">0</span></p>";

    this.scoreElement = document.getElementById("PlayerScore" + this.ID); //set score element …
Run Code Online (Sandbox Code Playgroud)

html javascript innerhtml

2
推荐指数
1
解决办法
1408
查看次数

OpenCL:clSetKernelArg 返回 CL_INVALID_ARG_SIZE

我是 OpenCL 的新手。我试图将 5 个参数传递到内核中:一个输入缓冲区、一个输出缓冲区、一个整数和 2 个输入缓冲区大小的本地数组。

//Create input/output cl_mem objects
cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY |
    CL_MEM_COPY_HOST_PTR, inputVector.size(), (void *)inputVector.data(), NULL);
cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
    inputVector.size(), NULL, NULL);

//get iterator from command line
cl_uint iterations = (cl_uint) atoi(argv[3]);
//std::cout << "iterations: " << iterations << std::endl
//cout confirms I'm getting this correctly

//Set kernel arguments
bool argOK = (CL_SUCCESS == clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&inputBuffer));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&outputBuffer));
argOK = argOK …
Run Code Online (Sandbox Code Playgroud)

c++ opencl

2
推荐指数
1
解决办法
5574
查看次数

将malloc的char*传递给构造函数,在char*上使用printf会产生分段错误

我有一个主要功能,称之为:

int main (int argc, char * argv[]) {
    char * x = (char*) malloc(100);
    x = "test string";
    printf("data: %s", x);
    StreamManager * SM = new StreamManager(NULL, x);
}
Run Code Online (Sandbox Code Playgroud)

StreamManager在这里有一个构造函数:

StreamManager::StreamManager(ConnectionManager * CMin, char * data) {
    printf("Creating StreamManager\n");
    printf("%s\n", data);
    printf("done");

    ...
}
Run Code Online (Sandbox Code Playgroud)

调用它给出了输出:

data: test stringCreating StreamManager
test string
Segmentation fault (core dumped) 
Run Code Online (Sandbox Code Playgroud)

为什么?它不应该被终止吗?

编辑:即使在更改后问题仍然存在.

主要:

char * x = (char*) malloc(100);
strcpy(x, "This is a test");
StreamManager * SM = new StreamManager(NULL, x);
Run Code Online (Sandbox Code Playgroud)

构造器:

printf("Creating StreamManager\n"); …
Run Code Online (Sandbox Code Playgroud)

c++ string pointers c-strings char

-1
推荐指数
1
解决办法
58
查看次数

标签 统计

c++ ×2

c-strings ×1

char ×1

html ×1

inform7 ×1

innerhtml ×1

javascript ×1

opencl ×1

pointers ×1

string ×1