ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Script is out of memory... Whatever that means
person icon
dekon_17
Registered User
Quote
2024-08-28 22:06:40

I wanted to make a "3D text" in my game. And I've decided to add "special symbols". For example, 'smile'. To get this symbol, it needs to be in text as '<smile>' to appear. Example:
HUD_Message ("I'm happy!<smile>", 1) //text, scale

Problem is, when I tried it with two symbols, I got an error, saying 'out of memory'. Even worse - in some cases the game just froze, not responding. Regular text works fine, but, is it because of those symbols at the start and end?
Detection for those symbols looks like this:
for (var k = 0; k < text.length; k++)
{
if (k > 0)
length += 0.2 * scale; //not important here
if (text [k] != ' ') //console says that this line is getting out of memory
{
var end = k;
if (text [k] == '<')
{
end = text.indexOf ('>') - 1; //getting symbol name
k += 1;
}
var L = ccbGetSceneNodeFromName ('letter.' + text.substring (k, end + 1)); //getting a letter. Or a symbol, if it is a symbol of course
...
Am I doing something wrong? Not that I'd be surprized, but, whatever...

person icon
just_in_case
Moderator
Quote
2024-08-29 05:04:27

I am not totally sure, but if K is negative then I think it will go in an infinite loop, or out of bound and might result in a memory overflow causing an out of memory error.


You can do some extra checks to ensure that index is not out of bound or -1. and ">" is found.

Though I am not sure if that's the case.

person icon
dekon_17
Registered User
Quote
2024-08-29 08:48:07

Okay, seems like you were close enough. I tried looking through 'k' value (value on each loop), and, well, I found the problem. Only, it's not that it's negative. It's that 'end' is always the same number. One thing I forgot to mention here is that, at the end of cycle, 'k' is being set to 'end' value. That means, infinite loop, as you've said. Fixed it by adding starting point to 'indexOf':
end = text.indexOf ('>', k) - 1;
Guess I shouldn't do programming late at night... Regardless, thanks for help.

person icon
okeoke
Registered User
Quote
2024-08-29 11:23:18

Hi Dekon,

You could probably simplify the flow a lot by simply parsing every character one by one, without using indexOf.

I hope I get what you're doing correctly:
const str = 'String <smile> string <clap>.'
const outcome = [];

let emojiStr = '';
let isEmoji = false;

for (var i = 0; i < str.length; i++) {
if (str[i] !== '<' && str[i] !== '>') {
if (!isEmoji) {
// get letter str[i]
print(str[i]);
} else {
emojiStr += str[i];
}
} else {
if (emojiStr) {
// get emoji emojiStr
print(emojiStr);
}
emojiStr = '';
isEmoji = !isEmoji;
}
}


Basically in case character is not < or > you simply get the node with corresponding character. In case it faces "<" it switches switches isEmoji to true, and starts accumulating characters in to emojiStr. As it faces ">" it switches isEmoji back, and you also get the emoji node. It switches isEmoji back to false, and keeps capturing individual symbols.

Edit: just read your last message. Good it is fixed.

person icon
j9907
Guest
Quote
2024-08-29 18:20:00

You guys are legends for doing this kind of work. Just wanted to say that. I certainly envy you. :)

person icon
josevaldo
Registered User
Quote
2024-10-18 12:23:25

Hello! I am very new to coppercube and my very basic knowledge is in Lazarus Pascal (I know exactly where I can use codes in my application).

Please, when using javascript in my games where can I use it so that it works. Please, a complete list of where I can be applying javascript and how it can be used?

person icon
andgameplay
Registered User
Quote
2024-10-18 17:17:35

Hi josevaldo, Im happy in see new devs in coppercube engine, welcome!

You can use javascript for a great list of actions ans behaviors, look this list, explain better how to use javascript in Coppercube!

https://www.ambiera.com/coppercu...

CopperCube JavaScript reference

CopperCube provides a very simple interface to manipulate all aspects of a 3D scene. See CopperCube Scripting overview for a short description on how to do this. This file lists all available functions.

Most of these functions manipulate so called 'scene nodes'. A scene node is nothing more than a 3d object with a position, rotation, scale, its materials and children. The name 'scene node' is there because CopperCube is internally using a scene graph to represent the 3d scene.

Scene Node Handling
ccbCloneSceneNode
ccbGetActiveCamera
ccbSetActiveCamera
ccbGetChildSceneNode
ccbGetRootSceneNode
ccbGetSceneNodeChildCount
ccbGetSceneNodeProperty
ccbSetSceneNodeProperty
ccbGetSceneNodeFromName
ccbGetSceneNodeMaterialCount
ccbGetSceneNodeMaterialProperty
ccbSetSceneNodeMaterialProperty
ccbRemoveSceneNode
ccbSetSceneNodeParent
ccbSetSceneNodePositionWithoutCollision

Events
ccbRegisterKeyDownEvent
ccbRegisterKeyUpEvent
ccbRegisterMouseDownEvent
ccbRegisterMouseUpEvent
ccbRegisterOnFrameEvent
ccbUnregisterOnFrameEvent

Drawing
ccbDrawColoredRectangle
ccbDrawTextureRectangle
ccbDrawTextureRectangleWithAlpha

Collision
ccbGet3DPosFrom2DPos
ccbGet2DPosFrom3DPos
ccbGetCollisionPointOfWorldWithLine
ccbDoesLineCollideWithBoundingBoxOfSceneNode
Various
ccbEndProgram
ccbLoadTexture
ccbGetMousePosX
ccbGetMousePosY
ccbSetMousePos
ccbGetScreenWidth
ccbGetScreenHeight
ccbSetCloseOnEscapePressed
ccbSetCursorVisible
ccbSwitchToScene
ccbPlaySound
ccbStopSound
ccbGetCopperCubeVariable
ccbSetCopperCubeVariable
ccbReadFileContent
ccbWriteFileContent
ccbFileExist
ccbFileDelete
ccbGetPlatform
ccbInvokeAction
ccbGetCurrentNode
ccbCleanMemory
ccbSwitchToFullscreen
ccbDoHTTPRequest
ccbCancelHTTPRequest
ccbCreateMaterial
ccbSetShaderConstant
ccbSetPhysicsVelocity
ccbUpdatePhysicsGeometry
ccbAICommand
ccbSteamSetAchievement
ccbSteamResetAchievements
ccbSaveScreenshot
ccbSaveTexture
ccbSwitchToCCBFile
print
system

Only in the editor
confirm
alert
prompt
editorAddSceneNode
editorFocusPosition
editorGetFileNameFromDialog
editorGetSelectedSceneNode
editorGetSelectedTexture
editorUpdateAllWindows
editorRegisterMenuEntry
editorSetSelectedSceneNode
editorImportStatic3DMesh
editorImportAnimated3DMesh

Mesh Editing
ccbGetSceneNodeMeshBufferCount
ccbRemoveMeshBuffer
ccbAddMeshBuffer
ccbGetMeshBufferVertexCount
ccbGetMeshBufferIndexCount
ccbAddMeshBufferIndex
ccbGetMeshBufferIndexValue
ccbSetMeshBufferIndexValue
ccbAddMeshBufferVertex
ccbGetMeshBufferVertexPosition
ccbSetMeshBufferVertexPosition
ccbGetMeshBufferVertexTextureCoord
ccbSetMeshBufferVertexTextureCoord
ccbGetMeshBufferVertexNormal
ccbSetMeshBufferVertexNormal
ccbGetMeshBufferVertexColor
ccbSetMeshBufferVertexColor
ccbUpdateSceneNodeBoundingBox


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 |