Will the outcomes be corresponding in this random behaviour tree?

closed account (367kGNh0)
Hello,

Here are the key parts of two behaviour tree with random outcomes. Not seen in the code i should specify, the trees are in the same method. All other code for random in c++ (e.g #define <ctime> ) are specified elsewhere.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

	srand(time(0));
	int PencilTextl = 1 + rand() % 8;

{
		if (PencilTextl == 1)
		{
			fiUscore->setTexture("Pencil and paper HMS3.png");
		}
		else if (PencilTextl == 2)
		{
			fiUscore->setTexture("Pencil and paper HMS2.png");
		}
		else if (PencilTextl == 3)
		{
			fiUscore->setTexture("Pencil and paper HMS10.png");
		}
		else if (PencilTextl == 4)
		{
			fiUscore->setTexture("Pencil and paper HMS7.png");
		}
		else if (PencilTextl == 5)
		{
			fiUscore->setTexture("Pencil and paper HMS6.png");
		}
		else if (PencilTextl == 6)
		{
			fiUscore->setTexture("Pencil and paper HMS11.png");
		}
		else if (PencilTextl == 7)
		{
			fiUscore->setTexture("Pencil and paper HMS4.png");
		}
		else if (PencilTextl == 8)
		{
			fiUscore->setTexture("Pencil and paper HMS5.png");
		}
	}
	{
		if (PencilTextl == 1)
		{
			sixUscore->setTexture("Pencil and paper HMS5.png");
		}
		else if (PencilTextl == 2)
		{
			sixUscore->setTexture("Pencil and paper HMS2.png");
		}
		else if (PencilTextl == 3)
		{
			sixUscore->setTexture("Pencil and paper HMS1.png");
		}
		else if (PencilTextl == 4)
		{
			sixUscore->setTexture("Pencil and paper HMS4.png");
		}
		else if (PencilTextl == 5)
		{
			sixUscore->setTexture("Pencil and paper HMS9.png");
		}
		else if (PencilTextl == 6)
		{
			sixUscore->setTexture("Pencil and paper HMS11.png");
		}
		else if (PencilTextl == 7)
		{
			sixUscore->setTexture("Pencil and paper HMS11.png");
		}
		else if (PencilTextl == 8)
		{
			sixUscore->setTexture("Pencil and paper HMS3.png");
		}
	}


I just ask, will the two behaviour tree outcomes always be corresponding, or would they be completely random and un-related?
Last edited on
If you're asking if PencilTextl is always the same in both blocks of code, then the answer is yes.

TBH, you can do away with a lot of code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const char *fiUscoreNames[] = {
    "Pencil and paper HMS3.png",
    "Pencil and paper HMS2.png",
    "Pencil and paper HMS10.png",
    "Pencil and paper HMS7.png",
    "Pencil and paper HMS6.png",
    "Pencil and paper HMS11.png",
    "Pencil and paper HMS4.png",
    "Pencil and paper HMS5.png",
};
const char *sixUscoreNames[] = {
    "Pencil and paper HMS5.png",
    "Pencil and paper HMS2.png",
    "Pencil and paper HMS1.png",
    "Pencil and paper HMS4.png",
    "Pencil and paper HMS9.png",
    "Pencil and paper HMS11.png",
    "Pencil and paper HMS11.png",
    "Pencil and paper HMS3.png",
};
int PencilTextl = rand() % 8;
fiUscore->setTexture(fiUscoreNames[PencilTextl]);
sixUscore->setTexture(sixUscoreNames[PencilTextl]);
		
closed account (367kGNh0)
Thanks @salem c

That closes this, but do you know how I can ensure both are random without making two

int name = rand()
?

I cannot tell if your code is the solution, or advice to use less code
Last edited on
closed account (367kGNh0)
found a way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const char *activities[] = {
			"Pencil and paper HMS1.png",
			"Pencil and paper HMS2.png",
			"Pencil and paper HMS3.png",
			"Pencil and paper HMS4.png",
			"Pencil and paper HMS5.png",
			"Pencil and paper HMS6.png",
			"Pencil and paper HMS7.png",
			"Pencil and paper HMS8.png"
			"Pencil and paper HMS9.png",
			"Pencil and paper HMS10.png",
			"Pencil and paper HMS11.png",
			"Pencil and paper HMS12.png",
	};


	auto Pcov = AutoPolygon::generatePolygon("Pencil cover.png");
	auto stencil = Sprite::create(Pcov);
	stencil->setScale(2, 3);
	stencil->runAction(MoveBy::create(3, Point(1000, 0)));
	stencil->setPosition(Vec2(-1270, -1230));

	clipper->setStencil(stencil);
	clipper->setInverted(true);

	auto fiUscore = Sprite::create(activities[rand() % 11]);
	fiUscore->setPosition(Vec2(-810, -1230));
	fiUscore->setScale(0.8);
	clipper->addChild(fiUscore);

	auto seUscore = Sprite::create(activities[rand() % 11]);
	seUscore->setPosition(Vec2(-930, -1230));
	seUscore->setScale(0.8);
	clipper->addChild(seUscore);

Topic archived. No new replies allowed.