I need help scripting a lens for count up instead of count down

TSMUSTY
TSMUSTY Posts: 3
edited March 2023 in Programming #1

this is the scrip I have :

**//@input int startDateDay
//@input int startDateMonth
//@input int startDateYear

//@input SceneObject countUpText

var startDate = new Date(startDateYear, startDateMonth - 1, startDateDay);
var today = new Date();

var timeDiff = Math.abs(today.getTime() - startDate.getTime());
var daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));

var countUpTextComponent = countUpText.getComponent("Component.Text");

if (countUpTextComponent) {
countUpTextComponent.text = "Day " + daysDiff;
}
**

I keep getting this error message:
**
11:32:54 ReferenceError: identifier 'startDateYear' undefined
at [anon] (Script.js:7) preventsyield **

Answers

  • Bakari Mustafa
    Bakari Mustafa Posts: 174 🔥🔥🔥

    It looks like you’re getting a ReferenceError because the startDateYear variable is not defined. This error can occur if you haven’t assigned a value to the startDateYear input field in the Inspector panel. Make sure that you have entered a value for the startDateYear input field in the Inspector panel and that it is an integer

  • 𝕵𝖔𝖊𝖑 𝕯𝖈𝖔𝖘𝖙𝖆🤘😠🎸
    edited March 2023 #3

    @TSMUSTY

    Count UP Script

    // -----JS CODE-----
    //@input int startDateDay
    //@input int startDateMonth
    //@input int startDateYear
    
    // For 3D Text only change Component.Text to Component.Text3D
    //@input Component.Text countUpText
    // Component.Text works for Both "Text Object" & "Screen Text"
    
    startDateDay = script.startDateDay
    startDateMonth = script.startDateMonth
    startDateYear = script.startDateYear
    
    var startDate = new Date(startDateYear, startDateMonth - 1, startDateDay);
    var today = new Date();
    
    var timeDiff = Math.abs(today.getTime() - startDate.getTime());
    var daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
    
    if (script.countUpText) {
        script.countUpText.text = "Day " + daysDiff;
    }
    

    Count Down Script

    // -----JS CODE-----
    //@input int endDateDay
    //@input int endDateMonth
    //@input int endDateYear
    
    // For 3D Text only change Component.Text to Component.Text3D
    //@input Component.Text countDownText
    // Component.Text works for Both "Text Object" & "Screen Text"
    
    endDateDay = script.endDateDay;
    endDateMonth = script.endDateMonth;
    endDateYear = script.endDateYear;
    
    var endDate = new Date(endDateYear, endDateMonth - 1, endDateDay);
    var today = new Date();
    
    var timeDiff = Math.abs(endDate.getTime() - today.getTime());
    var daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24)) + 1;
    
    if (script.countDownText) {
    script.countDownText.text = "Day " + daysDiff;
    }
    
    

    Bookmark for Reference

  • TSMUSTY
    TSMUSTY Posts: 3

    thanks @𝕵𝖔𝖊𝖑 𝕯𝖈𝖔𝖘𝖙𝖆🤘😠🎸 But the count up script is still counting down, I need it to start at 1- till the main date. not from the highest date to the lowest.

  • TSMUSTY
    TSMUSTY Posts: 3

    I just figured it out thanks