Ir para conteúdo

Lísias de Castro

Members
  • Total de itens

    4
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre Lísias de Castro

  • Classificação
    Bean Dragon
  • Data de Nascimento Dezembro 11

Informações Pessoais

  • Sexo
    Masculino

Últimos Visitantes

587 visualizações
  1. Lísias de Castro

    Erro em mysqli_select_db

    Ola. Estou criando um sistema de carrinho em php e pra isso preciso de um banco de dados. Pra não ficar chamando todas as funções a cada vez que a pagina atualiza, decidi usar a função mysqli_select_db, que verifica se o db existe e caso não exista, entre nas funções e crie. Porém, ao chamar a função quando o db não existe o php lança um "erro não capturado" e trava o layout. Se eu chamo o código sem o mysqli_select_db o código roda, porem chamando as funções a cada atualização. Poderia ser algum erro na api, ou tem uma nova forma pra pegar o tipo mysqli no php8? Esse é o código que eu chamo pra salvar os dados: ```php public function save($host,$user,$pass,$db){ $connection = mysqli_connect($host, $user, $pass); if($connection){ if(mysqli_select_db($connect,$db)){ } $dbCreator = "CREATE DATABASE IF NOT EXISTS ".$db; if(mysqli_query($connection, $dbCreator)){ //echo "Database created successfully"."</br>"; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($connection); return 0; } $tableCreator = "CREATE TABLE IF NOT EXISTS `".$db."_tb` (". "`name` VARCHAR(64) NOT NULL,". "`price` REAL,". "`amount` SMALLINT,". "`barcode` BIGINT NOT NULL PRIMARY KEY,". "`lot` VARCHAR(64) NOT NULL,". "`manufactured` VARCHAR(10) NOT NULL,". "`maturity` VARCHAR(10) NOT NULL". ");"; $insert = "INSERT INTO ".$db."_tb (`name`, `price`, `amount`, `barcode`, `lot`, `manufactured`, `maturity`) ". "SELECT ". "\"$this->name\",". "\"$this->price\",". "\"$this->amount\",". "\"$this->barcode\",". "\"$this->lot\",". "\"$this->manufactured\",". "\"$this->maturity\"". " FROM dual WHERE NOT EXISTS(SELECT * FROM $db"."_tb WHERE barcode = '$this->barcode')LIMIT 1;"; if(mysqli_select_db($connection,$db)){ if(mysqli_query($connection,$tableCreator));//echo "Tabela ".$db."_tb criada com sucesso.<br/>"; if(mysqli_query($connection,$insert));//echo "Dados inseridos com sucesso em $db"."_tb<br/>"; } mysqli_close($connection); return 1; } return 0; } ```
  2. Lísias de Castro

    trajeto linear em linguagem c

    Ola, sou Lísias e gostaria de saber se alguém poderia me ajudar nessa tarefa tão difícil para finalizar minha biblioteca. Eu fiz um motor de jogos, e nele já consegui implementar todas as funções básicas para um uso primário. Fazendo a criação de jogos simples através dela. Mas estou desenvolvendo um rpg, e resolvi fazer com que os personagens atirem a longa distância. Porém, para que isso aconteça, tenho que fazer com que o objeto a ser atirado sempre corra em linha reta. Criei uma função que faz com que todos os objetos se movam na tela, mas ela não funciona de uma maneira linear. O que posso modificar nessa função para que ela me proporcione isso? static STATUS place_user_move(OBJECT_SET * U, BP32 x, BP32 y) { if (U == NULL)return (Off); if (U->x_route == x) { if (U->y_route > y) { U->y_route -= U->y_speed; U->where_stop_but(U, NORTH); if (U->y_route < y) { U->y_route = y; U->where_stop(U); return (On); } } if (U->y_route < y) { U->y_route += U->y_speed; U->where_stop_but(U, SOUTH); if (U->y_route > y) { U->where_stop(U); U->y_route = y; return (On); } } return (Off); } if (U->y_route == y) { if (U->x_route > x) { U->x_route -= U->x_speed; U->where_stop_but(U, WEST); if (U->x_route < x) { U->where_stop(U); U->x_route = x; return (On); } } if (U->x_route < x) { U->x_route += U->x_speed; U->where_stop_but(U, EAST); if (U->x_route > x) { U->where_stop(U); U->x_route = x; return (On); } } return (Off); } if (U->x_route > x) { U->x_route -= U->x_speed; if (U->x_route < x)U->x_route = x; if (U->y_route > y) { U->y_route -= U->y_speed; U->where_stop_but_and(U, NORTH, WEST); if (U->y_route < y)U->y_route = y; } if (U->y_route < y) { U->where_stop_but_and(U, SOUTH, WEST); U->y_route += U->y_speed; } } if (U->x_route < x) { U->x_route += U->x_speed; if (U->x_route > x)U->x_route = x; if (U->y_route < y) { U->y_route += U->y_speed; U->where_stop_but_and(U, SOUTH, EAST); if (U->y_route > y)U->y_route = y; } if (U->y_route > y) { U->y_route -= U->y_speed; U->where_stop_but_and(U, NORTH, EAST); if (U->y_route < y)U->y_route = y; } } return (Off); } PLACE_CALL STATUS PLACE_TYPE place_user_route(CHAINED * user, BP32 x, BP32 y) { if (user && USER_C(user->it)->object && bit_is_on(USER_C(user->it)->object->status, OBJECT_VISIBLE)) { OBJECT_SET * U = USER_C(user->it)->object; if (U->x_route == x && U->y_route == y) { obj_where_stop_all(U); return (On); } //printf("xs %f ys %f\n",object->x_speed,object->y_speed); return (place_user_move(U, x, y)); } return (Off); } #define sign(x) ((x > 0) ? 1 : ((x < 0) ? -1 : 0) ) PLACE_CALL STATUS PLACE_TYPE place_user_straight(CHAINED * user, BP32 x1, BP32 y1) { if (user && USER_C(user->it)->object && bit_is_on(USER_C(user->it)->object->status, OBJECT_VISIBLE)) { OBJECT_SET * O = USER_C(user->it)->object; BP32 dx, dy; dx = x1 - O->x_route; dy = y1 - O->y_route; static BP32 x = -1, y = -1, p = -1; if (x == -1)x = O->x_route; if (y == -1)y = O->y_route; if (p == -1)p = 2 * dy - dx; printf("x %lf y %lf\n", x, y); if (x < x1) { if (p >= 0) { y = y + 1; p = p + 2 * dy - 2 * dx; } else { p = p + 2 * dy; } x = x + 1; } else { O->x_route = x; O->y_route = y; x = -1; y = -1; p = -1; return (On); } O->x_route = x; O->y_route = y; x = -1; y = -1; p = -1; } return (Off); } a função user_place_straight foi minha tentativa de implementar bresenham que promete fazer o que estou tentando. Isso é o que fá fiz com o motor: https://www.youtube.com/watch?v=nuLi_lB6c4Y&feature=youtu.be Mas até agora não estou conseguindo resultado
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.