Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Simple actions

Somedude15
Guest
Quote
2023-11-24 20:29:28

Hi, i modified one of the actions when i was making my game "Where are you brother" a time ago. now i want to share what i did, it's a dumb thing. I needed the action "action_Read_Specific_Line" (Read a specific line of text from a file) be capable to read the line using a integer variable, instead of typing the line manually each time, it's a small change i know, but maybe somebody will find this usefull. the code is this
/*
<action jsname="action_Leer_Linea_Con_Variable" description="Lee una linea con variable">
<property name="Filename" type="string" default="Filename.txt" description="Enter the Filemname to be entered"/>
<property name="Nombre_Variable" type="string" default="" description="Enter the name of variable with int to be printed"/>
<property name="overlay" type="scenenode" />
</action>
*/
action_Leer_Linea_Con_Variable = function () {
};

action_Leer_Linea_Con_Variable.prototype.execute = function (currentNode)
{
// variables to be created
var text = ccbReadFileContent(this.Filename);
var lines = text.split("\n");
//this.Line_to_print = ccbGetCopperCubeVariable(this.Nombre_Variable);
this.length = lines.length + 1 - ccbGetCopperCubeVariable(this.Nombre_Variable);

// draw the specified line on the 2D Overlay
var renderlines = lines[lines.length-this.length];
this.effect = renderlines;
ccbSetSceneNodeProperty(this.overlay, 'Draw Text', true);
ccbSetSceneNodeProperty(this.overlay, 'Text', this.effect);

};




I also create a new code from scratch (almost) with help of chatgpt, this new code do the same thing as before but it also apply a typewritter effect while showing the text.
[code]/*
<action jsname="action_ReadLineAndType" description="Read Line and Typewriter Effect">
<property name="Filename" type="string" value="filename.txt" description="Enter the filename to be loaded"/>
<property name="LineVariable" type="string" value="LineNumber" description="Enter the variable containing the line number"/>
<property name="OverlayNode" type="scenenode" description="Select the 2D overlay node where the text will be displayed"/>
<property name="Speed" type="integer" default="50" description="Enter the typing speed"/>
</action>
*/

action_ReadLineAndType = function () {
'use strict';
this.ReType = true;

};

action_ReadLineAndType.prototype.execute = function (currentNode) {
'use strict';
var me = this;
this.registeredFunction = function() { me.Type();};
this.startTime = (new Date()).getTime();
this.endTime = this.startTime + this.Speed;


ccbRegisterOnFrameEvent(me.registeredFunction);

};

action_ReadLineAndType.prototype.Type = function()
{
var now = (new Date()).getTime();
// Get the line number from the specified variable
var lineNumber = ccbGetCopperCubeVariable(this.LineVariable);

// Load text from file
var text = ccbReadFileContent(this.Filename);
var lines = text.split("\n");

// Ensure the line number is within bounds
lineNumber = Math.min(Math.max(lineNumber, 1), lines.length);

// Get the specified line
var lineToType = lines[lineNumber - 1]; // Adjust to 0-based index

// Get the specified overlay
var overlay = this.OverlayNode;


// Set up typewriter effect variables
if (this.ReType) {
this.typeIndex = 0;
this.ReType = false;
}
// Typewriter effect logic

if (this.typeIndex <= lineToType.length && now > this.endTime) {
var partialText = lineToType.substring(0, this.typeIndex);
ccbSetSceneNodeProperty(overlay, 'Draw Text', tr


Somedude15
Guest
Quote
2023-11-24 20:32:25


/*
<action jsname="action_ReadLineAndType" description="Read Line and Typewriter Effect">
<property name="Filename" type="string" value="filename.txt" description="Enter the filename to be loaded"/>
<property name="LineVariable" type="string" value="LineNumber" description="Enter the variable containing the line number"/>
<property name="OverlayNode" type="scenenode" description="Select the 2D overlay node where the text will be displayed"/>
<property name="Speed" type="integer" default="50" description="Enter the typing speed"/>
</action>
*/

action_ReadLineAndType = function () {
'use strict';
this.ReType = true;

};

action_ReadLineAndType.prototype.execute = function (currentNode) {
'use strict';
var me = this;
this.registeredFunction = function() { me.Type();};
this.startTime = (new Date()).getTime();
this.endTime = this.startTime + this.Speed;


ccbRegisterOnFrameEvent(me.registeredFunction);

};

action_ReadLineAndType.prototype.Type = function()
{
var now = (new Date()).getTime();
// Get the line number from the specified variable
var lineNumber = ccbGetCopperCubeVariable(this.LineVariable);

// Load text from file
var text = ccbReadFileContent(this.Filename);
var lines = text.split("\n");

// Ensure the line number is within bounds
lineNumber = Math.min(Math.max(lineNumber, 1), lines.length);

// Get the specified line
var lineToType = lines[lineNumber - 1]; // Adjust to 0-based index

// Get the specified overlay
var overlay = this.OverlayNode;


// Set up typewriter effect variables
if (this.ReType) {
this.typeIndex = 0;
this.ReType = false;
}
// Typewriter effect logic

if (this.typeIndex <= lineToType.length && now > this.endTime) {
var partialText = lineToType.substring(0, this.typeIndex);
ccbSetSceneNodeProperty(overlay, 'Draw Text', true);
ccbSetSceneNodeProperty(overlay, 'Text', partialText);
this.typeIndex++;
this.endTime = now + this.Speed;

}
if (this.typeIndex >= lineToType.length && now > this.endTime){
this.typeIndex = 0;
this.endTime=now*2;
ccbUnregisterOnFrameEvent(this.registeredFunction);

}

}





Guest
Guest
Quote
2023-11-25 06:45:38

Nice one @Somedude, but you could have also used JIC's dialogue manager instead of merging two of his actions together.

I think the Dialogue Manager has all the features that you need, it has a typewriter text animation and loading variable, reading text from files everything, and much more than that, the visual novel template is by far the best thing I've seen in the community.
I mean this guy makes life so much easier, I am becoming a fanboy day by day, whenever, Coppercube sucks, this guy comes like hold my sword, I am the Knight who will save the little CopperCube princes from the giant demons (Unity/Unreal) out there.

Huge respect for him, and thanks for sharing your stuff as well, maybe I or someone else can use it for small projects where we don't need the extra stuff, that comes with dialogue manager.


just_in_case
Moderator
Quote
2023-11-26 09:24:49

Thanks a lot @guest, but please do get yourself registered so that I can be aware of my fans too.
you probably should praise work of others as well, there are lots of people who are helping the community in one way or another, I can myself name a few like @hadoken, @sven, @samgrady, @okeoke and some anonymous users with guest names, it will be much better if their work gets shared in the community and people use them.

I personally don't like it when people treat me with these kinds of compliments, I am not special so don't treat me as if I am unique or something like that, I am very simple guy who loves to do stuff within the community and help the people but lately due to some haters and fans like you, who probably try to mess up the community by overpraising my stuff and give birth to haters for me.

because of these overgrowing numbers of haters, I keep myself away from answering threads here, and is less active on the forums.

So pleae don't praise me or my stuff like that, I am not that worthy to get all those fake praises and all.

If you are a true fan then you will understand it, and stop overexposing my stuff, be respectful to work of other people as well and appreciate their efforts.
hope you understands.


Guest
Guest
Quote
2023-11-27 09:07:09

Oooh, I am sorry, I didn't expected that kind of reaction from your side.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (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