Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
well... humble try

aloan
Registered User
Quote
2020-06-18 06:05:01

ccbSetCopperCubeVariable("animEuWalking", 1);
ccbSetCopperCubeVariable("animEuWalk", 1);

if (animEuWalk == 1)
ccbSetCopperCubeVariable("animEuWalking", 1);
ccbSetCopperCubeVariable("npcIsCarried", 0);
if (animEuWalking > 4)
ccbSetCopperCubeVariable("animEuWalking", 1);
I put this code into an every few 1000ms and created an overlay fetching the variable animEuWalking to see if at every second I would see its value increase up to 4 then reset to 1 again.
But all I see is the variable value stuck in 1 and it does not add... ., how do we ask CC to add to a variable?
Also it says animEuWalk is not defined. As you can see, I did declare animEuWalk in the second line! or did i not? lol...

Update: I added these 2 lines and it stopped complaining about the not defined error. But there is still no addition going on to the variable animEuWalking.
var animEuWalk;
var animEuWalking;
Funny that I had to declare them like this though, as I thought that writing ccbset would actually declare them!


just_in_case
Moderator
Quote
2020-06-18 10:23:06

There is a difference between coppercube variables and native javascript behavior, what you are doing is setting the coppercube variable, the thing is that you also need to get the coppercube variable value.

the error you were getting of variable not defined is due to that only. you need to declare javascript native variables too.

here is the solution to your problem.




var animEuWalk = ccbGetCopperCubeVariable("animEuWalk");
var animEuWalking = ccbGetCopperCubeVariable("animEuWalking");

if (animEuWalk == 1)
ccbSetCopperCubeVariable("animEuWalking", animEuWalking+1);
ccbSetCopperCubeVariable("npcIsCarried", 0);
if (animEuWalking > 4)
ccbSetCopperCubeVariable("animEuWalking", 1);



in above code i removed the set coppercube variable as you are using the every few seconds behavior for this script. so using the ccbSetCoppercubeVariable will reset the value of the variables to 1 everytime it is executed, so you need to use this with before first drawing behavior or with something else ..

i will recommend you to set all of your coppercube variables before first drawing...

also there was no increment operation has done by you for the variable animEuWalking so i added +1 for increment of variable, you can also use ++ operand for increment ..

also i don't know the use of variable animEuWalk but as you have used it in the above code so i left it as it is...

set animEuWalk and animEuWalking both variable to value 1 , with the behavior before first drawing do something and then use the above code with every few seconds.. i believe the addition of variable animEuWalking will be performed...

hope that helps...


aloan
Registered User
Quote
2020-06-18 18:41:19

oh thank you JIC! :D - I'll check and play with it and see!
That is going to the free town simulation ccb I am sharing with you all on the showcase thread as a separate JS text file which is part of the ccb and can be downloaded on my Google Drive on the post.
Once all is running up, I'll update the JS. So far the JS is growing and looking good and working. The more I put there, the more I delete from the hidden codings within the editor.
It is the best option having the logic laid down on one single text file, then hidden inside lots of menus and windows as is the case with behaviors and actions..
Here is the (working fine) Javascript so far without the changes/addition: (for me, typing it this way is more organized than having indentations as everything is under everything accordingly :D. It will be the first time I include the IF statement on the code :D
🔎︎


UPDATE: Wow, wow weee!!!! it worked!!!! Just In Case, you're the man!!! I had to change number 4 to 3 so the variable would only go up to 4 then reset back to 1.

This 1 to 4 stuff is the walking animation I have set for the main character. if 1 right leg forward, if 2 both legs together, if 3 left leg forward, if 4 both legs together, then the Loop :D
So, if right leg is forward and value is 1, then I make the main character's right leg forward Node/model show its visible texture, making all other node textures invisible (legs together and left leg forward) and so on!
Just so people are not in the dark: I am using 3 distinct models (all sharing the same positions as they are parented)! each with their walking pose (1: a model with legs together This is the Parent node, 2 a model with right foot forward and left foot backward-This is a child of the first model, 3 a model with right foot backward and left foot forward-This is a child of the first model). One of them has visible texture while the others invisible pngs! so their texture is made visible depending on which step is made.

Hopefully this will allow me to clean a lot of editor events and bring it to text. So the next update to the ccb will come with the updated JS file. Cheers!


aloan
Registered User
Quote
2020-06-19 17:22:02

Sad news! I guess I learned that the load texture does not actually change the texture. It just loads it ONE time and so you can't use that for animation... I spent a whole day trying to figure out but burned out in the wee hours until I had to stop to sleep with no success, and so I am trying to figure out an alternative. I do not want to resort to using the editor behavior.action, but wanted to do in pure javascript... Here is the code (I am using an image not because I want, but because if I paste the code in thext form, I go over the writing limit of the post, so I had to upload this image to my website and post it here)
I'll see if I prepare a ccb with the animation later or tonight so it can be looked at!
🔎︎



count2rfeit
Registered User
Quote
2020-06-19 18:00:14

I was looking at this awhile back - this link might get you some help...

https://blog.usejournal.com/lets...


aloan
Registered User
Quote
2020-06-19 18:34:02

wrote:
I was looking at this awhile back - this link might get you some help...

https://blog.usejournal.com/lets...
I'll sure have a read! thank you! :D

Update: I was checking it there and so it shows programming with another engine besides Copper... anyhoo.....

An idea (light bulb) just lit in my head, that there is ONE more Golden try!!! YESSSS!!! (lIke Jim Carrey in Dumb and Dumber once said) So You're telling me there's a chance........ :D yep,,,, so I will try (lastly try) to animate using alternating positions!!!! so whatever pose node/model needs to be ON during the walk cycle will be on the floor while the other 2 nodes/models will wait below ground level.. Clever Huh? I hope it works. For that I will even copy/clone another ccb just to test the idea out. I am believing it will work. All so I can get with text and run away from menus and windows. Let's see... going to work on it now...........

Well it isn't there yet, when I tried to make vertical moves using the function moveNodeWithoutCollision all nodes moved to the game's area 0,0,0 position. I know I need to use a relative to self position, but I guess that is not possible with the javascript api as it is not listed there as a function! :(
here is another newest method I tried with no success: (So far I am abandoning coding for this kind of stuff and going back to hidden/hard to organize logic in CC's menus and windows)
// first drawing
var PositionOfCube = ccbGetSceneNodeProperty(pfAle, "Position");
var moveUp = PositionOfCube.y + 8;
var moveDown = PositionOfCube.y - 8;
// every 200ms
if (alewalk == 1)
ccbSetSceneNodeProperty(pfAleStep1, "Position", PositionOfCube.y, moveUp);
ccbSetSceneNodeProperty(pfAle, "Position", PositionOfCube.y, moveDown);
ccbSetSceneNodeProperty(pfAleStep2, "Position", PositionOfCube.y, moveDown);

if (alewalk == 2)
ccbSetSceneNodeProperty(pfAle, "Position", PositionOfCube.y, moveUp);
ccbSetSceneNodeProperty(pfAleStep1, "Position", PositionOfCube.y, moveDown);
ccbSetSceneNodeProperty(pfAleStep2, "Position", PositionOfCube.y, moveDown);

if (alewalk == 3)
ccbSetSceneNodeProperty(pfAleStep2, "Position", PositionOfCube.y, moveUp);
ccbSetSceneNodeProperty(pfAle, "Position", PositionOfCube.y, moveDown);
ccbSetSceneNodeProperty(pfAleStep1, "Position", PositionOfCube.y, moveDown);

if (alewalk == 4)
ccbSetSceneNodeProperty(pfAle, "Position", PositionOfCube.y, moveUp);
ccbSetSceneNodeProperty(pfAleStep1, "Position", PositionOfCube.y, moveDown);
ccbSetSceneNodeProperty(pfAleStep2, "Position", PositionOfCube.y, moveDown);



just_in_case
Moderator
Quote
2020-06-20 15:46:39

For the loading of the texture part you can refer to ky age of empire clone dropped demo project... And can checkout the script...

Load texture will load rhe texture but you can use the same yo play diffrent animations dynamically....
Just check the script out....

Here is the link to the thread...
https://www.ambiera.com/forum.ph...

The script is very lengthy so you might have to look through the script but i think i have commented out the texture sections...

Hope this will help...

Aditionally if you want to know

Ccbsetscenenodematerial property can be used to change a loaded texture....
Thats how it is done to load a texture and then change it dynamically by comparing time and interval between the frames to create a perfect blend of the sprites...




aloan
Registered User
Quote
2020-06-20 16:05:38

Thanks a lot for getting my hopes up Justin!
🔎︎
Have a burger :D
I've been busy 2 days with the ccb, and just this morning for the first time remembered that I could put 12 2D overlays atop the screen, each showing what's going on with important variables, and so was able to pinpoint some bugs.

Now I'll be separating events that happen in 200ms (only for animation frame changes) and 66ms (for key input check and variable set changes) because I had put all of that together in the 200ms and so some animation type transitions (not frames) took a bit to respond showing some discrepancies on the screen (like if I dropped an Npc I was holding in my arms, the normal pose would show before the "Being carried pose " would be invisible, for example).
But yeah, I'll check all that you sent me! in fact I had downloaded the agess ccb a while back, so I'll check the script and the ccbSetSceneNodeMaterialProperty feature!

I couldn't be more excited with the steps I'm taking... merging code, turning to code (in text form) instead of dozens of windows of actions and behaviors and now checking variables with Overlays...
Can't wait to share the new Hytale inspired Town simulation CCB and Javascript file with all of you in the forum, as soon as it is in a nice playable state!
On another good and last news, before uploading, I will be merging all the files related to the CCB (sounds, scripts, exe) inside a zip file so you don't have to click on separate links like it is now on the town simulation download post.
Here I am in town checking if variables are working (sheesh, I forgot to remove my face from the main char hahahah - yeah sometimes I become the character - fun, fun, fun!):
🔎︎



just_in_case
Moderator
Quote
2020-06-20 18:24:50

This is exactly how i check if my variables and positions are working correctly... By printing them on 2d overlays.... It allows me to have look at all variables at once most of the time they are co related with each other if a variable is true then set that variable to something and so on....
So it becomes really easy to have an eye on the code while executing the game....
This saves a lot of time...
😇😊😉😉


aloan
Registered User
Quote
2020-06-21 05:43:03

One last thing to really make this work and close this thread with a Golden Key:

Yes it worked to change the texture, but ONLY the First texture, so only the right foot step forward model's visible clothing is changed,
like it is ignoring the other 2 models (feet together and left foot forward model!
I tried adding +, &&, +"//"+, tried merging, tried using multiple IFs and nothing, lol, so Here is the code:
if (alewalk == 0) 
ccbSetSceneNodeMaterialProperty(alestep1, 0, "Texture1", roupa);
ccbSetSceneNodeMaterialProperty(ale, 0, "texture1", roupainv);
ccbSetSceneNodeMaterialProperty(alestep2, 0, "texture1", roupainv);
So only the first line of the ccbSetSceneNodeMaterialProperty Is working but not the other 2!
As the screenshot shows, when the right foot model shows in (texture loads, the feet together model doesn't get dressed with its invisible texture,
so you see two models instead of one.
🔎︎

Btw, all 3 models and (visible + invisible) textures are correctly referenced at first drawing! (see code)
var ale = ccbGetSceneNodeFromName("ale");
var alestep1 = ccbGetSceneNodeFromName("alestep1");
var alestep2 = ccbGetSceneNodeFromName("alestep2");
var roupa = ccbLoadTexture("ale.png");
var roupainv = ccbLoadTexture("aleinv.png");
I did look into the agess javascript file but this type of 3 texture changes to 3 models at one variable value at once, I don't think happens there ;D
Also this animation technique happens at each 200ms for a nice 4 frame walking animation!
Oh and Here is the CCB!!!https://drive.google.com/file/d/...


just_in_case
Moderator
Quote
2020-06-21 07:19:30

if (alewalk == 0) 
ccbSetSceneNodeMaterialProperty(alestep1, 0, "Texture1", roupa);
ccbSetSceneNodeMaterialProperty(ale, 0, "texture1", roupainv);
ccbSetSceneNodeMaterialProperty(alestep2, 0, "texture1", roupainv);


as per the above code mentioned by you here there is a very silly mistake here.....
the property name here is case sensitive which is in your case is Texture1 which is absolutely true for the first line but will not work for the rest of others as the first letter "T" is in lowercase in the other lines the property... So always be aware javascript is case sensitive...

didn't downloaded the ccb yet as i am on a mobile device right now but am pretty sure changing "texture1" into "Texture1" will solve the problem...



aloan
Registered User
Quote
2020-06-21 14:48:39

Update: Just In Case has ironed out the code to be as simple as possible, so here is the result! worked great (He will be fixing the first frame issue, a minor thing soon)!
🔎︎

Here is the (updated) golden Easy Animation CCB for all to enjoy and use in your projects (coming in the next town update!!!
https://drive.google.com/file/d/...
UPDATE June 23rd 2020: Just In Case has fixed it! so the ccb has been updated to its final 6th version! enjoy and Thank you Just In Case!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (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© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact