ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator How to get book to appear after a certain distance
person icon
luposian
Registered User
Quote
2023-08-11 05:42:54

Right now the book is simply there. You can pick it up, it displays the paper, and then the paper disappears.

But I want the book to not be there until you've traveled 5% of the terrain and a multiple thereof (up to 25%). And then it appears in front of you a few paces away, where you can then pick it up and see the paper and go on your way til the next book shows up.

I'm assuming it would be somehow tied to the pedometer (since that tells you how much area you've covered), but not sure what or how. Any hints? emoji icon_grin

person icon
sven
Registered User
Quote
2023-08-11 08:50:10

If you have access to your percent values as coppercube variable..
Then you can do..

If percent 5 then
Set book position -relative to scenenode (wolf)
I would place book in front of wolf but higher..
Book with collide when moved(affected by gravity)
So it falls to the ground infront of wolf somewhere.

(Otherwise book may spawn inside the mountain if ground not flat)

There is many ways how to do that.

person icon
luposian
Registered User
Quote
2023-08-11 11:46:31

wrote:
If you have access to your percent values as coppercube variable..
Then you can do..

If percent 5 then
Set book position -relative to scenenode (wolf)
I would place book in front of wolf but higher..
Book with collide when moved(affected by gravity)
So it falls to the ground infront of wolf somewhere.

(Otherwise book may spawn inside the mountain if ground not flat)

There is many ways how to do that.

In looking at the Javascript code, of both Pedometer and Area Coverage, I'm not seeing anything easily identifiable to hook into. Of course, my lack of understanding of programming, in general, doesn't help. I'm finding bits and pieces that match up, between the javascript code in the files and CopperCube javascript instructs, but I sense I'm not quite grasping something. Quite elusive. Like I can almost figure it out, but not quite. Like it's just out of reach... taunting me... if only I could wrap my brain around it. Almost, but not quite.

person icon
luposian
Registered User
Quote
2023-08-11 11:49:06

Pedometer Code


// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_LPSNPedometer" description="Pedometer v0.1">
<property name="writeDistanceInUnitsToVariable" type="string" default="distanceInUnits" />
<property name="writeUserFriendlyDistanceToVariable" type="string" default="distanceUserFriendly" />
<property name="magicNumber" type="float" default="0.043" />
<property name="ignoreYMovement" type="bool" default="true" />
</behavior>
*/

behavior_LPSNPedometer = function () {
this.lastPosition = null;
this.totalDistance = null;
};

behavior_LPSNPedometer.prototype.onAnimate = function (node, timeMs) {
let playerPos = ccbGetSceneNodeProperty(node, 'Position');
if (this.ignoreYMovement) playerPos.y = 0;

if (!this.lastPosition) {
this.lastPosition = playerPos;
return false;
}

this.totalDistance += playerPos.substract(this.lastPosition).getLength();
this.lastPosition = playerPos;

// write to variable
ccbSetCopperCubeVariable(this.writeDistanceInUnitsToVariable, this.totalDistance.toFixed(2));
ccbSetCopperCubeVariable(this.writeUserFriendlyDistanceToVariable, (this.totalDistance * this.magicNumber).toFixed(2));

return false;
}


person icon
luposian
Registered User
Quote
2023-08-11 11:51:32

Area Coverage Code (it was too long to display the text here)

https://files.catbox.moe/022s7h....

person icon
sven
Registered User
Quote
2023-08-11 11:54:26

SECOND script you sent has percent variable:

<property name="writeVisitedPercentToVariable" type="string" default="percentVisitedNodes" />

in here its default named "percentVisitedNodes" (but if you changed it then use changed name)

if you didnt change default string then variable for percent is :
percentVisitedNodes

now you can use it.. :[coppercube editor IF action)
IF percentVisitedNodes =5 THEN

(depends on the value.. it may show 5.0023 or something and its never 5 % -so you may use different approach with if statement.)

different approach:[coppercube editor IF action)
IF percentVisitedNodes >5 THEN
IF percentVisitedNodes <6 THEN

do book stuff here
(also use maybe variable here to detect that BOOK1 is already in action)

ENDIF
ENDIF

person icon
luposian
Registered User
Quote
2023-08-11 12:22:55

wrote:
SECOND script you sent has percent variable:

<property name="writeVisitedPercentToVariable" type="string" default="percentVisitedNodes" />

in here its default named "percentVisitedNodes" (but if you changed it then use changed name)

if you didnt change default string then variable for percent is :
percentVisitedNodes

now you can use it.. :[coppercube editor IF action)
IF percentVisitedNodes =5 THEN

(depends on the value.. it may show 5.0023 or something and its never 5 % -so you may use different approach with if statement.)

different approach:[coppercube editor IF action)
IF percentVisitedNodes >5 THEN
IF percentVisitedNodes <6 THEN

do book stuff here
(also use maybe variable here to detect that BOOK1 is already in action)

ENDIF
ENDIF

This is what I see in the editor.

https://files.catbox.moe/hwyjyo....

But those are words that you can't attach a number or action to (like a submenu to a lot of behaviors). Where is the "THEN" or "ENDIF" you're talking about? They're not in the Javascript code.

person icon
sven
Registered User
Quote
2023-08-11 12:31:05

You dont need to edit javascript.
Just use coppercube action..

On ROOT
Add behavior- everyFewMs do something.
Now you can add IF action

In if action you can compare if percentValue=5 then do something..
Do book

Tomorrow if i have time i can make simple tutorial of basic coppercube stuff for you..
Its very simple actually..

person icon
luposian
Registered User
Quote
2023-08-11 21:45:29

wrote:
You dont need to edit javascript.
Just use coppercube action..

On ROOT
Add behavior- everyFewMs do something.
Now you can add IF action

In if action you can compare if percentValue=5 then do something..
Do book

Tomorrow if i have time i can make simple tutorial of basic coppercube stuff for you..
Its very simple actually..

Any help I can get, to make sense of what I need to do, is appreciated.

Update! Ok, I finally figured out what you were saying!

When I did that, the book is gone (initially). I set it to > 2%, to test. When it (my travelled distance) reaches that threshold, the book appears where it normally is. When I touch it, the page appears and then disappears 5 seconds later, as designed. However...

The book never disappears when I touch it and it just stays there. Why is the book not disappearing when I touch it, even though the behavior I attached to it (page appear/disappear) work as intended?

"I sense a conflict in The Force." emoji icon_grin

Update! Ok, I finally figured out what I needed to do, to solve THAT problem.

I needed to make the book INVISIBLE from the start. Then I needed to set up the variable condition for the book's appearance, but only after it reached the threshold value (>2) without an Else condition. Then, I needed to tell the book to delete itself (not just make itself invisible) as part of the proximity condition!

Now the book is invisible, appears after you've covered 2%+ of the terrain, shows the piece of paper when you touch the book (which also makes the book vanish) and the paper disappears after 5 seconds!

Whew!

Now I need to see about setting up the condition for the book reappearing at multiples of 5% and repeating this cycle.

And, if I'm not mistaken, I think I can achieve that by chaining Else conditions on the first Variable environment. Hmm?

Update! Trial and error... OH, WHAT A TERROR!

Whew! Getting this figured out is NOT fun, but I'm making it work!

I first tried cloning the book node (to save time, of course)... that didn't work. Why? Because the cloned books all have the same self-destruct command (delete node)... so they ALL die at the same time as the first book! Ugh! And I assume, if I removed the self-destruct code from ANY of them, they'd ALL file suit and NONE of them would self-destruct.

So, gotta go the LONG way around. Gotta create 5 different books and 5 different overlays (the overlays makes sense, because they're different hints). But wish there was an easier way of copying the size/location of the books/overlays instead of having to manually type them in each time. Oh well...

So, now I have two books that appear at two different distances (1% and 2%; just to get things figured out faster, without wandering around forever)

Now comes the hard part (or at least something that I haven't been helped with yet)... how to get the book to appear in front of Luposian, off to the side (or somewhere nearby, if he's right up against a mountain), wherever he is at the specified distance(s).

person icon
luposian
Registered User
Quote
2023-08-12 07:18:28

Ok, rather than expanding my previous post ad infinitum, I'll make another one.

SUCCESS!!! With a small caveat...

I've figured out how to get the 1st book to appear next to my character, via relative positioning to my character, but... it keeps wanting to always be that same distance from me! In other words, it keeps moving, as I move!

Is there a way for it to appear in the location it pops to (if I animate the movement (with a speed of about 5000ms), it's like being chased by a book!emoji icon_grin), without moving as I move? It doesn't move so fast that I can't tag it before it moves again, but... it would be more realistic if it simply "appeared" there (stationary) and you just move to pick it up (touch it).

person icon
sven
Registered User
Quote
2023-08-12 09:04:46

Book moves because you dont place it one time as it should but you are placeing it multiple times..

You need to rechek what you have done with your IF statements.


You can use variable booksDone=0

Now in if statement check
Is percent> 5 and is booksDone0
Then set booksDone to 1
Place book one

Now you can be sure book will be placed one time

For second book check
Is percent >10
Is booksDone 1
Set booksDone to 2
Place second book

Now you can be sure book 2 will be placed one time

And same thing with all books.

person icon
luposian
Registered User
Quote
2023-08-12 09:58:25

I'll get to that next. I've uploaded my 1st preliminary version to Itch tonight. I've struggled all day getting to this point. I deserve a break. emoji icon_grin

Enjoy!

person icon
luposian
Registered User
Quote
2023-08-12 22:08:23

wrote:
Book moves because you dont place it one time as it should but you are placeing it multiple times..

You need to rechek what you have done with your IF statements.


You can use variable booksDone=0

Now in if statement check
Is percent> 5 and is booksDone0
Then set booksDone to 1
Place book one

Now you can be sure book will be placed one time

Ok, would I use the Else option after first action?

The book is placed Relative to the player's position. But that is wherever the player is, so how do you make where it first appears, the spot it stays, when you don't know where that location is? You can't use a static location or a vector, because you don't know where the player will be, when the distance traveled threshold is reached. And the book simply follows the player, according to the "relative position" rule. You would have to know where (coordinates) it first appears and then tell it to stay at the same location. But how?

person icon
sven
Registered User
Quote
2023-08-13 01:48:34

I made custom script for placeing book infront of player.
script will also makes sure that book will be placed on to ground.

Here is example:
https://drive.google.com/file/d/...

in example you see how i use IF statement and how i make sure that IF will be never true if its once completed.

using ELSE has other usage..
IF walkedPercent=5% THEN
do stuff if its 5%
ELSE
do stuff if its not 5% but any other value-that means its always doing something.
or use another IF here (but i see no point for this)
ENDIF

person icon
luposian
Registered User
Quote
2023-08-13 07:21:02

Getting tired of seeing error message to my replies, so I'm just posting my reply here... ugh!
---
It's going to take me awhile to sort though your .ccb, as it looks like it uses a lot of complicated event sequences. A lot more detailed than what I did. But I'm sure I'll figure it out eventually.
emoji icon_grin


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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