Results 1 to 3 of 3

Thread: help please, variable definition

  1. #1

    Exclamation help please, variable definition

    Hi,

    please, can you tell if I made a mistake ?

    testagain0.tbasic
      
    uses "CONSOLE"
    
    #Include "easing4.tbasicu"
    
    dim etest as easing
    
    
    WaitKey
    
    easing4.tbasicu
    uses "math"
    
    
    
    Type easing
    
      totalDuration as DWORD Value = 0
      
    end type
    
    I think it's anormal I get this error :
    Code=173
    Description=TYPE error: missing AS clause in element definition
    Line=7
    LineCode=TOTALDURATION AS DWORD VALUE = 0
    Token=TOTALDURATION
    Additional=
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,083
    Blog Entries
    5
    Rep Power
    725
    Hi Sebastian,

    you cannot give member of UDT a default value.

    This is okay:
    Type easing
     
      totalDuration as DWORD
       
    end type
    
    This is not okay:
    Type easing
     
      totalDuration as DWORD VALUE 0
       
    end type
    
    totalDuration will be, as all numeric types, initialized to 0 by default.

    I understand it would be nice to initialize some non-default values, but it is not possible at the moment.

    There are some "close" solutions, like:

    uses "console"
    
    
    type easing
    
    
      totalDuration as dword
    
    
      function _create()
        me.totalDuration = 5 ' some default value
      end function
    end type
    
    
    dim e1 as easing ' -- will initialize with constructor, whoa!
    printl e1.totalDuration
    
    
    waitkey
    
    Petr
    Last edited by Petr Schreiber; 04-11-2019 at 20:48.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Quote Originally Posted by Petr Schreiber View Post

    I understand it would be nice to initialize some non-default values, but it is not possible at the moment.

    There are some "close" solutions, like:
    Right Petr ! I miss this help page about _create()

    This is indeed the good practice.

    But, again, the error description is very misleading.

    Thanks Petr.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. "The nationalist is by definition an ignoramus."
    By danbaron in forum Shout Box Area
    Replies: 0
    Last Post: 07-03-2012, 21:22
  2. New in next thinBasic: FOR with on-the-fly variable definition
    By ErosOlmi in forum thinBasic vaporware
    Replies: 16
    Last Post: 09-07-2008, 09:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •