Construct 3 with AI help

0 favourites
  • 7 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • I am trying to use AI tools to develop with C3

    and without luck

    looks like the construct doesn't accept what AI is doing

    for example, this code, Construct shows error on line 9, in "Function ConvertToGridCoord(x, y):" so, it can't start function, sometimes showing a null object'

    we can say that it is just bad AI code, but in unity it works quite good, so, I believe there are some mistakes in transition of the JS to construct JS

    Can it be resolved? maybe somebody has the same experience

    // Global variables
    Variables:
     cellSize = 118 
     cellHeight = 102 
     gridWidth = 10 
     gridHeight = 10 
    
    // Function for converting screen coordinates to grid coordinates
    Function ConvertToGridCoord(x, y):
     let qF = (Math.sqrt(3)/3 * x - 1/3 * y) / cellSize
     let rF = (2/3 * y) / cellSize
     let q = Math.round(qF)
     let r = Math.round(rF)
     let s = Math.round(-qF - rF)
     
     let qDiff = Math.abs(q - qF)
     let rDiff = Math.abs(r - rF)
     let sDiff = Math.abs(s - (-qF - rF))
     
     if (qDiff > rDiff && qDiff > sDiff):
     q = -r - s
     else if (rDiff > sDiff):
     r = -q - s
     
     return {q: q, r: r}
    
    // Function for converting grid coordinates to screen coordinates
    Function ConvertToScreenCoord(q, r):
     let x = cellSize * (Math.sqrt(3) * q + Math.sqrt(3)/2 * r)
     let y = cellSize * (3/2 * r)
     return {x: x, y: y}
    
    // Function to check if a cell is within the grid boundaries
    Function IsInGrid(q, r):
     return q >= 0 && q < gridWidth && r >= 0 && r < gridHeight
    
    // Function to get the neighbors of a cell
    Function GetNeighbors(q, r):
     let directions = [
     {q: 1, r: 0}, {q: 1, r: -1}, {q: 0, r: -1},
     {q: -1, r: 0}, {q: -1, r: 1}, {q: 0, r: 1}
     ]
     let neighbors = []
     for (let dir of directions):
     let newQ = q + dir.q
     let newR = r + dir.r
     if (IsInGrid(newQ, newR)):
     neighbors.push({q: newQ, r: newR})
     return neighbors
    
    // Function for pathfinding (A* algorithm)
    Function FindPath(startQ, startR, endQ, endR):
     let openSet = [{q: startQ, r: startR, g: 0, h: 0, f: 0, parent: null}]
     let closedSet = []
     
     while (openSet.length > 0):
     let current = openSet.reduce((min, item) => item.f < min.f ? item : min, openSet[0])
     
     if (current.q === endQ && current.r === endR):
     let path = []
     while (current):
     path.push({q: current.q, r: current.r})
     current = current.parent
     return path.reverse()
     
     openSet = openSet.filter(item => item !== current)
     closedSet.push(current)
     
     let neighbors = GetNeighbors(current.q, current.r)
     for (let neighbor of neighbors):
     if (closedSet.some(item => item.q === neighbor.q && item.r === neighbor.r)):
     continue
     
     let gScore = current.g + 1
     let isInOpenSet = openSet.some(item => item.q === neighbor.q && item.r === neighbor.r)
     
     if (!isInOpenSet || gScore < neighbor.g):
     let h = Math.abs(neighbor.q - endQ) + Math.abs(neighbor.r - endR)
     let f = gScore + h
     
     if (!isInOpenSet):
     openSet.push({q: neighbor.q, r: neighbor.r, g: gScore, h: h, f: f, parent: current})
     else:
     let existingNeighbor = openSet.find(item => item.q === neighbor.q && item.r === neighbor.r)
     existingNeighbor.g = gScore
     existingNeighbor.f = f
     existingNeighbor.parent = current
     
     return null // путь не найден
    
    // Events
    
    On start of layout:
     // Grid initialization (creating cell sprites)
     For q = 0 to gridWidth - 1:
     For r = 0 to gridHeight - 1:
     let pos = ConvertToScreenCoord(q, r)
     Create object Cell at (pos.x, pos.y)
    
    On Touch object Cell:
     let touchX = Touch.X
     let touchY = Touch.Y
     let gridCoord = ConvertToGridCoord(touchX, touchY)
     let path = FindPath(Ship.GridQ, Ship.GridR, gridCoord.q, gridCoord.r)
     
     if (path):
     Ship.PathToFollow = path
     Ship.CurrentPathIndex = 0
     System.Trigger("MoveShipAlongPath")
    
    System event: MoveShipAlongPath:
     if (Ship.CurrentPathIndex < Ship.PathToFollow.length):
     let nextCell = Ship.PathToFollow[Ship.CurrentPathIndex]
     let screenCoord = ConvertToScreenCoord(nextCell.q, nextCell.r)
     
     Ship.TweenPosition(screenCoord.x, screenCoord.y, 0.5, "ease-out-quad")
     Ship.GridQ = nextCell.q
     Ship.GridR = nextCell.r
     
     Ship.CurrentPathIndex += 1
     else:
     Ship.PathToFollow = null
     Ship.CurrentPathIndex = 0
    
    On TweenPosition completed for Ship:
     System.Trigger("MoveShipAlongPath")
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That looks like a mix between Python and Javascript, that won't work.

    And I have my doubts that an AI can do anything usable in construct.

    Maybe pure Javascript for scripting, but without understanding what the AI is generating, I think it will still not useful for you.

  • That looks like a mix between Python and Javascript, that won't work.

    And I have my doubts that an AI can do anything usable in construct.

    Maybe pure Javascript for scripting, but without understanding what the AI is generating, I think it will still not useful for you.

    i can understand JS, but the issue here is how to call construct behaviors like touch and other systems, AI can try to generate logic something as events, and as I see it is understanding how construct 3 is working. but it is hard to repeat events from AI, because you don't know, if will it work in the end haha

    with code things can be easier, just copy past and test, work or not, but we need a working code

    In unity AI can help very well, maybe we need specified construct 3 model for this job, or maybe somebody knows workarounds

  • My guess is that for Unity are so much more examples that an AI can lern from. For scripting in Construct there are only the manual and a few examples and that is not enough for useful code.

    I'm afraid if you want use scripting you have to go the hard way an learn it yourself.

  • My guess is that for Unity are so much more examples that an AI can lern from. For scripting in Construct there are only the manual and a few examples and that is not enough for useful code.

    I'm afraid if you want use scripting you have to go the hard way an learn it yourself.

    AI can help us, it helped me many times, for example, it helped me to make a script that converts Google Sheets pages into json to construct array

    And helped many times with small things that I forgot

    But the code that I showed above, is a very complex logical and math task, which is hard to realize

    So, it is good to have some skilled help

    I believe there are ways, AI models that will work with construct, we just need to find it

  • I have to agree with Asmodean, there just isn't enough of construct 3 to train the AI brain. In RPG maker (MZ) I can ask either Gemini or Chatgpt4o to write a javascript script and it is usually spot on. The AI even knows about things like addon library's and what they can help with (visustella).

    Alas, I haven't been able to get the AI to be much help in Construct 3.

    yours

    winkr7

  • yes, it is true, not much training, also, many AI models have serious issues with logic.

    But Clause AI is very good, it really doesn't know Construct 3 JS code well, cause it is a really rare thing, but I see it understands the construct well and does good logic and math.

    The only issue as I said, it is too long to reproduce his advice inside construct, at least much longer than just copy past a code block with all logic and math inside

    But if you said the code is completely wrong, so, no way, for sure

    I thought maybe we could change some methods, and it would work, in this case, anyway, this AI help could be very important

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)