Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
Cycle
Author Text

dekon_17
Registered User
Quote
2022-04-09 08:41:58

Well, now I found the real problem.
I think I mentioned earlier that I've used "for" cycle to create collisions between enemies so that they won't phase through eachother. Now, turns out this type of cycle breaks... Basicly everything. I tried to use it for spawn system as well (to give different names for enemies), and even in this type of its usage it just stops the entire game. Is there any alternatives or any type of cycle will act similarly in WebGL?


sven
Registered User
Quote
2022-04-09 09:05:08

This type of cycle doesnt break if you use it correct way.
You have a error there to fix -thats why it breaks all.


dekon_17
Registered User
Quote
2022-04-09 09:23:14

Hm-m, weird. I mean, when I tested this on Windows, it was fine, no crashes or something like that. It breaks in WebGL though - game just stops. Maybe cycle works a bit differently there?


dekon_17
Registered User
Quote
2022-04-09 09:24:12

This is the cycle I used for generating names:
for (B = 0; this.Empty == false; ++B)
{
var Obj = ccbGetSceneNodeFromName ("Infected" + B);
if (Obj)
this.Empty = false;
else
this.Empty = true;
};



Arcanjo
Guest
Quote
2022-04-09 09:32:32

You should create a box on the characters.
Set the texture of box to transparent.

Ready. There will collision among them.


dekon_17
Registered User
Quote
2022-04-09 09:38:24

Nah, Arcanjo, I've tried this already, for some reason it didn't work. And yeah, this will cause problems with hitting enemies if the box is way too big or problems with their collision if the box is way too small.


sven
Registered User
Quote
2022-04-09 10:34:44

I tested this and works.

i got error if VAR was not at the beginning of B
i dont know but it doesnt like this.Emty also
so i used var g



var g=0;
for (var B = 1; g < 1; B++)
{
var Obj = ccbGetSceneNodeFromName ("CP" + B);
if (Obj!=null)
{
g = 0;
}else{
g = 1;
ccbSetSceneNodeProperty(ccbGetSceneNodeFromName ("cc"), "Text", B);
}
}



dekon_17
Registered User
Quote
2022-04-09 11:32:24

So... Do I understand that right: it broke just because I did "B = 0" and not "var B = 0"? I mean, the part with "Empty"... Well, I remade this using "var Empty = 0" before cycle, that's for sure. And I did the same for AI script and it all... Works. I just don't know, I did a bit of ridiculous mistake for the second time this week.
🔎︎

Anyways, thanks you, sven, I really appreciated.


sven
Registered User
Quote
2022-04-09 12:13:39

Depends how your this.empty was defined you maybe had only mistake thats VAR not at the beginning of B.
With windows app it doesnt care but with webGL it gives error.

This script scans all my checkpoints and finds empty
from 0 to -- by using your loop


/*
<action jsname="action_1" description="1">
</action>
*/

action_1 = function()
{
this.Empty=false;
}


action_1.prototype.execute = function()
{


for (var B = 0; this.Empty===false; B++)
{
var Obj = ccbGetSceneNodeFromName ("CP" + B);
if (Obj)
{
this.Empty = false;
}else{
this.Empty = true;
ccbSetSceneNodeProperty(ccbGetSceneNodeFromName ("cc"), "Text", "emty"+B);
}
}


}



just_in_case
Moderator
Quote
2022-04-10 03:40:45

You can try using linepicks for the Collision checking for the AI, either by checking the collision with the bounding box of the scenenode or by getting the collision point of the world and check if that point lies in the radius of the AI, if it lies then perform the hit otherwise no-hit.

Regarding the For-loop, @sven has already answered
your question. However, As you are dealing with AI, I would like to suggest you not use pre-created AI, instead create one with different properties and then clone them during runtime.
You don't have to look them for in the scene like you are checking them in the example above with a for Loop.

As, it might affect the performance.

you can for example clone and spawn a new enemy after the previous one is dead, or can clone and spawn it on proximity of player with an object. It will also decrease the load time of your project if you are doing it for the webGL platform.




dekon_17
Registered User
Quote
2022-04-12 11:26:44

Hey, just_in_case! Sorry for a little late answer, I was busy doing some programming.

So, about collision... Well, it is not really by a bounding box. Instead, it check the length of a vector between two characters (current and cloned), but without Y-axis, since the location of the game is... Basically just a field with some stuff, so, it doesn't really matter.

You also suggested me to create my own AI, and, actually, it is what I wanted first, but I thought that it is hard and complicated. And also I threw away this decision because CopperCube shooting action works only with collision boxes, so, built-in AI can react on it, while I couldn't do something like that. Until now. As I said, I was doing some programming, and I somehow managed to do custom shooting action to work with "hit boxes" for my "main project", so, now I think I might try to make custom AI.

And about the amount of enemies, I did exactly what you suggested before I found the problem with cycle (loop) in WebGL. So, it clones a character, puts it into the "Enemies" folder, and this is what AI is constantly looking over to find collision. And if there are more than 20 enemies or no more of them to spawn, they... Well, they won't spawn, obviously.

And... I think I answered all what you suggested to me. So, thanks, just_in_case, I'll try to do my best (so, basically nothing, lol).


Arcanjo
Guest
Quote
2022-04-13 05:25:38

Dekon_17, you got solution about the problem?


dekon_17
Registered User
Quote
2022-04-13 06:51:44

Uhm... If you're talking about the problem with loop (or cycle), then yes, I understood what I did wrong (thanks to sven), so, I have a solution, yes.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact