Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to call the function moveUpB from inside the response.status(200).send part and I think that part is json, but I don't know that much about json. The response.status and moveUpB are inside the handleMove function. I have been trying everything to get it to work for weeks and I still have no idea. The rest of my code is there in case it is needed. I need to send data to a different website or server or something, and the response.status sends it. My move commands need to be in handlemove and if I try to use move commands above the response.status, they only execute once. If I try to use it below the response.status, it gives me an error. This makes me think that my move commands need to be called from inside the response.status part. I hope someone here can help me.

JavaScript
const express = require('express')

const PORT = process.env.PORT || 3000

const app = express()
app.use(bodyParser.json())

app.get('/', handleIndex)
app.post('/start', handleStart)
app.post('/move', handleMove)
app.post('/end', handleEnd)

app.listen(PORT, () => console.log(`Battlesnake Server listening at http://127.0.0.1:${PORT}`))

function handleIndex(request, response) {
  var battlesnakeInfo = {
    apiversion: '1',
    author: '',
    color: '#1c607d',
    head: 'caffeine',
    tail: 'leaf'
  }
  response.status(200).json(battlesnakeInfo)
}

function handleStart(request, response) {
  var gameData = request.body

  console.log('START')
  response.status(200).send('ok')
}

function handleMove(request, response) {
  var gameData = request.body


What I have tried:

Everything I could think of and nothing worked.
Posted
Updated 23-Feb-22 11:59am
v2
Comments
_Asif_ 24-Feb-22 2:44am    
Can you share your JSON data. Your question is not clear enough.

If they are, then you can't: json is not a language at all, it's a data format, and it has not idea of "executing" or even "functions": just data and data structures.
 
Share this answer
 
Comments
octopuscaat 23-Feb-22 13:53pm    
then what do i do? the code needs to send data to the servers and if i put my code above the response.status it executes once and i need it so send each turn. useing loops wont work because it needs to get through everything.
Quote:
I need to call the function moveUpB from inside the response.status(200).send part and I think that part is json, but I don't know that much about json.

Short answer: you don't.
Json is structured data, it never execute code, no matter what.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900