Godot making test questions

azzkicker1994azzkicker1994 Posts: 9Member

My goal is to have Godot make 2selections from 100 simple images (shapes). Using the 2 images, there will be 5 possible "answers" 4 of the answers will be the same image and the image that is different is the correct selection. I've managed to get 5 test images to see if i can make it happen, and i have my background and 5 image fields as well as the proper "spawn" locations (i managed to use a random spawner, but it's typically 4 of the same images" any help would seriously be appreciated, im using it as a studying tool. For the SIFT if anyone was interested.

Answers

  • MegalomaniakMegalomaniak Posts: 3,978Admin

    OK, so are you looking for someone to do it for you? In which case I can move this to the appropriate category(professional trade).

    Or are you asking how to go about developing such a thing? In which case I'd say your question is perhaps a bit too broad.

    Start by figuring out how to divide it up into smaller tasks that can be done in steps and try to figure out the optimal order for completing these tasks by following the steps. If you need any help with any one of these steps then it's a good time to ask more concise questions about achieving the specific task. This also makes it easier to give a clear and concise answer.

  • azzkicker1994azzkicker1994 Posts: 9Member

    I see, I apologize for the vagueness. I'm asking for advice, and I guess I don't know where to start. It all seems so simple!
    My first hurdle I would say is getting Godot to randomly select 2 images, randomly duplicate 1 of the images to place in 4 of the 5 spots (randomly of course) and then place the second image in the 5th spot.
    What is a good way to show my current coding so you can see what I'm working with?

  • azzkicker1994azzkicker1994 Posts: 9Member


    its a basic background, but you can see where the image slots are.

  • MegalomaniakMegalomaniak Posts: 3,978Admin

    You can either copy and paste code in your post, then highlight(select) all of it and press the code option under the format menu(paragraph icon), or the best is if you can share a minimal project only including the parts necessary to show your problem.

  • azzkicker1994azzkicker1994 Posts: 9Member
        extends Node2D
    
        #Grid Variables
        export (int) var width;
        export (int) var height;
        export (int) var x_start;
        export (int) var y_start;
        export (int) var offset;
    
        var possible_pieces = [
        preload("res://Scenes/piece_1.tscn"),
        preload("res://Scenes/piece_2.tscn"),
        preload("res://Scenes/piece_3.tscn"),
        preload("res://Scenes/piece_4.tscn"),
        preload("res://Scenes/piece_5.tscn")
        ];
    
        var all_pieces = [];
    
        # Called when the node enters the scene tree for the first time.
        func _ready():
            randomize();
            all_pieces = make_2d_array();
            spawn_pieces();
    
    
        func make_2d_array():
            var array  = [];
            for i in width:
                array.append([]);
                for j in height:
                    array[i].append(null);
            return array;   
    
        func spawn_pieces():
            for i in width:
                for j in height:
                    #chose a random number and store it
                    var rand = floor(rand_range(0, possible_pieces.size()));
                    #instance that pieces from array
                    var piece = possible_pieces[rand].instance();
                    add_child(piece);
                    piece.position = grid_to_pixel(i, j);
    
    
        func grid_to_pixel(column, row):
            var new_x = x_start + offset * column;
            var new_y = y_start + -offset *row;
            return Vector2(new_x, new_y);
    
    
    
        # Called every frame. 'delta' is the elapsed time since the previous frame.
        #func _process(delta):
        #   pass
    

    this is essentially all that there is so far, thank you for the help by the way.

  • MegalomaniakMegalomaniak Posts: 3,978Admin

    Could you describe your scene/node hierarchy a bit, I'm trying to recreate it on my end here.

  • azzkicker1994azzkicker1994 Posts: 9Member

    I'll do my best.
    I have one "scene" as node2d with a Sprite child node. I used that to create 5 inherited scenes and placed my pictures in the Sprites texture field. I named each one "piece_1" though 5.
    I think I bit off a bit more than I could chew in terms of scripting....
    I'm doing my best in terms of learning/research.
    here are the 5 images I've been using.




  • MegalomaniakMegalomaniak Posts: 3,978Admin
    edited September 2019

    @azzkicker1994 said:
    I'll do my best.
    I have one "scene" as node2d with a Sprite child node. I used that to create 5 inherited scenes and placed my pictures in the Sprites texture field. I named each one "piece_1" though 5.

    Yes I figured that out from your code, but the scene where your script is attached, Is that just a Node2D? or is there something else going on in there too?

    For the shapes I just created polygon2Ds representing numbers 1 through 5 which for my purposes should be functionally as good.

  • azzkicker1994azzkicker1994 Posts: 9Member

    no funny business, its all node2d. My "grid" node is just a node 2d, and that's were the script I pasted is located, its a child of the same node as my "background" image.

  • MegalomaniakMegalomaniak Posts: 3,978Admin

    Hmm, ok. I've been busy, but hopefully I can afford to take a hour or 2 to look at it tomorrow. If someone else wants to chip in and look at this though, hey. That would be great too.

  • azzkicker1994azzkicker1994 Posts: 9Member

    I guess when Megalomaniak comes around, people steer clear! No rush, I'm using it to help me study, and lord knows I have plenty else to study.
    thanks again for helping me out

  • MegalomaniakMegalomaniak Posts: 3,978Admin

    Ok, I've had a chance to take a quick look and it is working far as I can tell, so I guess I'm confused what your actual problem is. Getting it to only show 2 out of 5 shapes? Or something else?

  • azzkicker1994azzkicker1994 Posts: 9Member

    I get off work at 5 and i'll take a reference picture

  • azzkicker1994azzkicker1994 Posts: 9Member

  • MegalomaniakMegalomaniak Posts: 3,978Admin
    edited September 2019

    Ok, well, this should kind of work, except you can end up with a situation where it's all of the same shapes...

    extends Node2D
    
    export (int) var width = 5;
    export (int) var height = 1;
    export (int) var x_start = 420;
    export (int) var y_start = 270;
    export (int) var offset = 48;
    
    var possible_pieces = [
    preload("res://Scenes/piece_1.tscn"),
    preload("res://Scenes/piece_2.tscn"),
    preload("res://Scenes/piece_3.tscn"),
    preload("res://Scenes/piece_4.tscn"),
    preload("res://Scenes/piece_5.tscn")
    ];
    
    var all_pieces = [];
    # Called when the node enters the scene tree for the first time.
    func _ready():
        randomize();
        spawn_pieces();
    
    
    func spawn_pieces():
        var rand
        var piece
    
        for i in width:
            if i < 2:
                for j in height:
                    rand = floor(rand_range(0, possible_pieces.size()));
                    piece = possible_pieces[rand].instance();
                    self.add_child(piece);
                    piece.position = grid_to_pixel(i, j);
            elif i >= 2:
                for j in height:
                    piece = possible_pieces[rand].instance();
                    self.add_child(piece);
                    piece.position = grid_to_pixel(i, j);
    
    
    func grid_to_pixel(column, row):
        var new_x = x_start + offset * column;
        var new_y = y_start + -offset *row;
        return Vector2(new_x, new_y);
    

    edit: oh, and the first one is always the correct answer...

  • MegalomaniakMegalomaniak Posts: 3,978Admin
    edited September 2019

    Further tips I can give are that to check if the user is picking the correct answer you can add the correct node to a group named say "correct" for an example, and that you want to pick first two of the potential picks and add them to another array and fill the rest of the array with the incorrect node of the two, then use array sorting to faux-randomize it again and spawn from that one in order instead.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file