Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 1 Support › Read Infos from files

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4661

    johanna_g18

    Hey.

    For a v-play game i need to read data from a simple txt file. But how? Google results aren’t realy helpfully. Can somebody help me?

     

    best wishes

    Johanna

    #4662

    Christian
    Felgo Team

    Hi Johanna,

    since version 1.3 we support file reading with System::readFile(). However, in most cases you can achieve a better code style by defining a base QML file (like a LevelBase.qml) and then create multiple instances of it by subclassing this QML file.

    Cheers, Chris

    #4664

    johanna_g18

    After a failed VPlay update and a completely new installation VPlay 1.3 is running now đŸ™‚ And i’ve found the readFile() function.

    But we do not really understand why we need a base QML file. Do you mean for creating different levels?

    Greetings Johanna

    #4666

    Christian
    Felgo Team

    If you just read levels, it is easier to define the levels in QML file and you do not need the loading from a file.

    Have a look at the demo games like Squaby, where this concept is shown in detail.

    Consider the following code:

    LevelBase.qml:
    Item {
     // the blocks variant could be any array or a map you define in the levels
     property variant blocks
    }
    
    Level01.qml:
    LevelBase {
     // enter any level data here you need for your game
     blocks: [[10, 30, 50], [5, 10, 5]]
    }
    
    then, for loading the level:
    Loader {
     source: "Level01.qml" // select any level here, possibly from a level selection scene
    }

     

    This is the suggested workflow with QML. File reading is only necessary if you also want to save some files, which is not the case I guess.

    Cheers, Chris

    #4671

    johanna_g18

    ok. this sounds logical and easier than reading from a file đŸ™‚

    i’ve tried it. but i don’t understand how to get all the single stones out of my property in the BaseLevel.qml. So i have following qml files:

    BaseLevel.qml: contains a property with all data loaded from the Level.qml and a Loader (like shown in your post)

    Level01.qml: like shown in your post

    Stone.qml: implements mouse area, boxCollider, position, size of a stone. these data are saved in the property of the BaseLevel.qml. how can i access them?

     

    i’ve tried to get this information out of the code of Squaby but i couldn’t find what i searched for.. may you help me?

     

    Greetings, Johanna

    #4673

    Christian
    Felgo Team

    Hi Johanna,

    You can access the contents of the Loader with the item property. Please have look at the Loader documentation, or search for “Loader” in the demo games.

    Cheers, Chris

Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded