User prompt
add a global boolean "running". default false. Then prevent indicator and graph updates when running is false
Code edit (3 edits merged)
Please save this source code
User prompt
add a console log in indicator's updateYPosition like drawNextSegment
Code edit (3 edits merged)
Please save this source code
User prompt
in drawGraph callback log don't display decimals
User prompt
in drawGraph log don't display decimals
User prompt
same in "Segment drawn from'" log
User prompt
in drawGraph log don't display decimals
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'updatePosition')' in this line: 'valueIndicator.updatePosition(100); // Example stock price' Line Number: 120
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'var x = valueIndicator.x;' Line Number: 124
User prompt
the 1st graphPoints should be the start coordinates of valueIndicator
User prompt
remove the sample square
User prompt
Now compute the coordinates that of ValueIndicator will reach using stockValuesHistory and create a serie of points to pass to drawGraph
User prompt
modify the recursive `updateWidth` function to include a condition that compares the current time to the `endTime`. If the current time is greater than or equal to the `endTime`, the segment's width should be set to the final `distance` value, and the callback should be called if it is a function. Additionally, the recursive calls to `updateWidth` should be stopped to prevent further unnecessary updates.
User prompt
fix the condition to execute the callback is never met within the `updateWidth`
Code edit (1 edits merged)
Please save this source code
User prompt
add logs to drawGraph
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: callback is not defined' in this line: 'updateWidth(callback);' Line Number: 201
User prompt
Fix Bug: 'Uncaught ReferenceError: callback is not defined' in this line: 'updateWidth(callback);' Line Number: 201
User prompt
Update drawGraph (and if needed drawSegment) function in order to draw the segments one after the other
Code edit (1 edits merged)
Please save this source code
User prompt
call drawGraph to draw a sample square
User prompt
create a drawGraph(gameRef, points) global function. It takes a list of coordinates (at least 2) and calls drawSegment to draw segments between the points. eg. drawGraph(gameRef, [{x:0,y:0}, {x:100,y:0}, {x:100,y:100}, {x:0,y:100}, {x:0,y:0}]) will draw a square
===================================================================
--- original.js
+++ change.js
@@ -5,8 +5,11 @@
var ValueIndicator = Container.expand(function () {
var self = Container.call(this);
var indicatorGraphics = self.createAsset('valueIndicator', 'Current Stock Value Indicator', 0.5, 0.5);
self.updatePosition = function (price) {
+ if (!running) {
+ return;
+ }
// Position ValueIndicator based on the stock price
self.x = 0; // Start from the left side
self.y = 2732 / 2; // Start from the left side
var targetX = game.width / 2; // Center horizontally
@@ -34,8 +37,9 @@
var historyIndex = 0; // Start with the first value in the history
var updateYPosition = function updateYPosition() {
if (historyIndex < stockValuesHistory.length) {
var targetY = game.height / 2 - stockValuesHistory[historyIndex] * 10; // Scale the stock value for display
+ console.log('ValueIndicator moving to next position: ' + stockValuesHistory[historyIndex], 1366 - targetY);
var startY = self.y;
var duration = 1000; // Duration in milliseconds for Y movement
var startTime = Date.now();
var animateY = function animateY() {
@@ -51,9 +55,8 @@
};
animateY();
historyIndex++;
LK.setTimeout(function () {
- console.log('ValueIndicator moving to next position: ' + stockValuesHistory[historyIndex], targetY);
updateYPosition();
}, 1000); // Update position every second and add a new segment
}
};
@@ -109,8 +112,9 @@
// Initialize game elements
var player = new Player();
var stocks = [];
// Initialize stock values history with the first value of $10
+var running = false;
var stockValuesHistory = [10];
// Add 10 other random stock values
for (var i = 0; i < 10; i++) {
stockValuesHistory.push(Math.floor(Math.random() * 100) + 1);
@@ -126,8 +130,12 @@
var segmentWidth = graphWidth / stockValuesHistory.length;
// Set the first graphPoints to match the start coordinates of valueIndicator
var x = valueIndicator.x;
var y = valueIndicator.y;
+console.log('valueIndicator start at', {
+ x: Math.round(x),
+ y: Math.round(1366 - y)
+});
graphPoints.push({
x: x,
y: y
});
@@ -201,8 +209,11 @@
};
updateWidth();
}
function drawGraph(gameRef, points) {
+ if (!running) {
+ return;
+ }
console.log('Starting to draw graph');
if (points.length < 2) {
console.log('Not enough points to draw a graph segment.');
return;
A Technical dark background. Nothing just a gradiant of colors from black to dark blue. Theme : stock market. background
A modern clean empty rectangular button without borders. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
without shadow
a basic empty ui popup with a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.