How do you speficy the type of variable from python to C in Ctypes?

Currently I’m learning about C types. I have a piece of C code. It is not the whole code, but I think the rest is not relevant to share. The sin and cos function are defined above in the original code.

C:

double tan(f) double f;
{
       return sin(f)/cos(f); 

Python:

import ctypes

testlib = ctypes.CDLL('./testlib.so')

testlib.tan.argtypes = ctypes.c_double
teslib.tan.restype = ctypes.c_double

print(testlib.cos(2))

First I didn’t use the lines:

testlib.tan.argtypes = ctypes.c_double
teslib.tan.restype = ctypes.c_double

I got an output, but the ouput was 0. I thought that the double value was downcasted to an int.

What I want to achieve is that I send an double from python to C, and C will return me a double.

I’m already familiar with this documentation, but I didn’t manage to find the right answer:
https://docs.python.org/3/library/ctypes.html

Question: How should I modify my code to get the good output?

Ter

procedural programming – My code breaks as soon as I try to print a variable

EDIT: I think I figured out what was wrong. Since I was adding in Print(m) AFTER I ran the loop I had to clear my variables if I wanted to run the loop again. I guess my new question is, why did I have to clear m and x? I tried to rerun F(x_) to reset the function and I tried to rerun m=3 after but it just gave me strange results which I will attach below. What happens when I rerun F(x_) = x^2 Cos(x) + x + 3 after running the loop.


Original issue starts here
I’m running a For loop(and it needs to be a for loop) thats supposed to do newtons method on a function.
I’ll post the parts of the code that I think are needed to get the error

F(x_) = x^2 Cos(x) + x + 3
m = 3

For(i = 0, i < 5, i++,     
 F'(m);
 y = F(m) + F'(m) (x - m);
 x = (0 - F(m))/(F'(m))   + m;
 Print(N(F(x)));
 m = x

All of this code here works fine. The moment I add Print(m) or Print(x) in the loop it completely breaks and I do not know why.
The picture below is the code working BEFORE I add in Print(m) anywhere in the loop.
Code pre-the writing of Print(m)

admin – undefined variable get from switch select option

I try to make inside theme custom admin panel a switch select option. but i cannot get the value of switch case. following is my code:

 <?php  $bannerchange = $_POST('bannerchange');
    
    if( get_option('bannerchange') != get_option($bannerchange)) {
                $bannerchange = update_option( 'bannerchange', get_option($bannerchange));
    
    }

I can debug this problom with stright way?

if(isset($_POST('wphw_submit')) && $chk):?>
  <div id="message" class="updated below-h2">
    <p>Content updated successfully</p>
  </div>


  <?php endif;?>
      <form method="post" action="">

<select name="wphw_submit" onchange="this.form.submit()">
     <option value="page1"<?php if ($bannerchange == "page1") { echo " selected"; } ?>>Custom Departure</option>
     <option value="page2"<?php if ($bannerchange  == "page2") { echo " selected"; } ?>>Fixed Departure</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
 </div>
<input type="submit" name="wphw_submit" value="Save changes" class="button-primary" />
<?php

switch ($bannerchange) {
    case 'page2': ?>
        
        <p>two</p>

        <?php
        break;
    case 'page1':
        ?>
        <p>one</p>
        <?php
        break;
    }
    ?>

$bannerchange get always undefined. any help greatly appreciated.

unity – How can I access a variable on a script in another scene that I made it dontdestroyonload?

I need to get access to the variable flag loading from some script in another scene.
The variable loading in my main menu scene and I need to access it in scripts in my game scene.

I’m not sure if using dontdestroyonload in this case is the right way and I don’t want to make the loading variable public static either :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEditor;
using Cinemachine;
using UnityStandardAssets.Characters.ThirdPerson;

public class MenuController : MonoBehaviour
{
    #region Default Values
    (Header("Default Menu Values"))
    (SerializeField) private float defaultVolume;
    (SerializeField) private int defaultSen;
    (SerializeField) private bool defaultInvertY;

    (Header("Levels To Load"))
    public string _newGameButtonLevel;
    private string levelToLoad;

    public SceneFader sceneFader;
    public GameObject player;

    private int menuNumber;
    #endregion

    #region Menu Dialogs
    (Header("Main Menu Components"))
    (SerializeField) private GameObject menuDefaultCanvas;
    (SerializeField) private GameObject GeneralSettingsCanvas;
    (SerializeField) private GameObject graphicsMenu;
    (SerializeField) private GameObject soundMenu;
    (SerializeField) private GameObject controlsMenu;
    (SerializeField) private GameObject confirmationMenu;
    (Space(10))
    (Header("Menu Popout Dialogs"))
    (SerializeField) private GameObject noSaveDialog;
    (SerializeField) private GameObject newGameDialog;
    (SerializeField) private GameObject loadGameDialog;
    #endregion

    #region Slider Linking
    (Header("Menu Sliders"))
    (SerializeField) private Text controllerSenText;
    (SerializeField) private Slider controllerSenSlider;
    public float controlSenFloat = 2f;
    (Space(10))
    (SerializeField) private Text volumeText;
    (SerializeField) private Slider volumeSlider;
    (Space(10))
    (SerializeField) private Toggle invertYToggle;
    #endregion

    public bool loading = false;

    #region Initialisation - Button Selection & Menu Order
    private void Start()
    {
        DontDestroyOnLoad(this);
        menuNumber = 1;
    }
    #endregion

    //MAIN SECTION
    public IEnumerator ConfirmationBox()
    {
        confirmationMenu.SetActive(true);
        yield return new WaitForSeconds(2);
        confirmationMenu.SetActive(false);
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (menuNumber == 2 || menuNumber == 7 || menuNumber == 8)
            {
                GoBackToMainMenu();
                ClickSound();
            }

            else if (menuNumber == 3 || menuNumber == 4 || menuNumber == 5)
            {
                GoBackToOptionsMenu();
                ClickSound();
            }

            else if (menuNumber == 6) //CONTROLS MENU
            {
                ClickSound();
            }
        }
    }

    private void ClickSound()
    {
        GetComponent<AudioSource>().Play();
    }

    #region Menu Mouse Clicks
    public void MouseClick(string buttonType)
    {
        if (buttonType == "Controls")
        {
            controlsMenu.SetActive(true);
            menuNumber = 6;
        }

        if (buttonType == "Graphics")
        {
            GeneralSettingsCanvas.SetActive(false);
            graphicsMenu.SetActive(true);
            menuNumber = 3;
        }

        if (buttonType == "Sound")
        {
            GeneralSettingsCanvas.SetActive(false);
            soundMenu.SetActive(true);
            menuNumber = 4;
        }

        if (buttonType == "Exit")
        {
            Debug.Log("YES QUIT!");
            Application.Quit();
        }

        if (buttonType == "Options")
        {
            menuDefaultCanvas.SetActive(false);
            GeneralSettingsCanvas.SetActive(true);
            menuNumber = 2;
        }

        if (buttonType == "LoadGame")
        {
            menuDefaultCanvas.SetActive(false);
            loadGameDialog.SetActive(true);
            menuNumber = 8;
        }

        if (buttonType == "NewGame")
        {
            menuDefaultCanvas.SetActive(false);
            newGameDialog.SetActive(true);
            menuNumber = 7;
        }
    }
    #endregion

    public void VolumeSlider(float volume)
    {
        AudioListener.volume = volume;
        volumeText.text = volume.ToString("0.0");
    }

    public void VolumeApply()
    {
        PlayerPrefs.SetFloat("masterVolume", AudioListener.volume);
        Debug.Log(PlayerPrefs.GetFloat("masterVolume"));
        StartCoroutine(ConfirmationBox());
    }

    public void ControllerSen()
    {
        controllerSenText.text = controllerSenSlider.value.ToString("0");
        controlSenFloat = controllerSenSlider.value;
    }

    #region ResetButton
    public void ResetButton(string GraphicsMenu)
    {
        if (GraphicsMenu == "Audio")
        {
            AudioListener.volume = defaultVolume;
            volumeSlider.value = defaultVolume;
            volumeText.text = defaultVolume.ToString("0.0");
            VolumeApply();
        }

        if (GraphicsMenu == "Graphics")
        {
            controllerSenText.text = defaultSen.ToString("0");
            controllerSenSlider.value = defaultSen;
            controlSenFloat = defaultSen;

            invertYToggle.isOn = false;
        }
    }
    #endregion

    #region Dialog Options - This is where we load what has been saved in player prefs!
    public void ClickNewGameDialog(string ButtonType)
    {
        if (ButtonType == "Yes")
        {
            // Here to use a script to load the start game scene slowly smooth fade to black
            // Then fade back to transparent when loading/loaded the scene game !!!!!
            //SceneManager.LoadScene(_newGameButtonLevel);

            // When making new game to reset everything state scene everythig.
            // Including the uiSceneText for example.
            // To check how to reset everything to default !
            loading = false;
            newGameDialog.SetActive(false);
            StartCoroutine(sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, _newGameButtonLevel));
        }

        if (ButtonType == "No")
        {
            GoBackToMainMenu();
        }
    }

    public void ClickLoadGameDialog(string ButtonType)
    {
        if (ButtonType == "Yes")
        {
            //if (PlayerPrefs.HasKey("SavedLevel"))
            //{
            //Debug.Log("I WANT TO LOAD THE SAVED GAME");
            //LOAD LAST SAVED SCENE
            //levelToLoad = PlayerPrefs.GetString("SavedLevel");
            //SceneManager.LoadScene(levelToLoad);
            loading = true;
            newGameDialog.SetActive(false);
            StartCoroutine(sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, _newGameButtonLevel));

            //}

            /*else
            {
                Debug.Log("Load Game Dialog");
                menuDefaultCanvas.SetActive(false);
                loadGameDialog.SetActive(false);
                noSaveDialog.SetActive(true);
            }*/
        }

        if (ButtonType == "No")
        {
            GoBackToMainMenu();
        }
    }
    #endregion

    #region Back to Menus
    public void GoBackToOptionsMenu()
    {
        GeneralSettingsCanvas.SetActive(true);
        graphicsMenu.SetActive(false);
        soundMenu.SetActive(false);

        VolumeApply();

        menuNumber = 2;
    }

    public void GoBackToMainMenu()
    {
        menuDefaultCanvas.SetActive(true);
        newGameDialog.SetActive(false);
        loadGameDialog.SetActive(false);
        noSaveDialog.SetActive(false);
        GeneralSettingsCanvas.SetActive(false);
        graphicsMenu.SetActive(false);
        soundMenu.SetActive(false);
        menuNumber = 1;
    }

    public void ClickQuitOptions()
    {
        GoBackToMainMenu();
    }

    public void ClickNoSaveDialog()
    {
        GoBackToMainMenu();
    }
    #endregion
}

At the top line 56 :

public bool loading = false;

Inside Start at line 61 :

DontDestroyOnLoad(this);

Then inside the method for starting a new game in line 207 :

loading = false;

And in the method that loading a saved game in line 228 :

loading = true;

Now that I know when it’s starting a new game and when it’s loading a game I want to use this loading variable in some scripts in my game scene.

For example this script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SceneFader : MonoBehaviour
{
    #region FIELDS
    public GameObject fadeOutUIGameobjectImage;
    public float fadeSpeed = 0.8f;

    private MenuController menuController;
    private Image fadeOutUIImage;

    private void Start()
    {
        
    }

    public enum FadeDirection
    {
        In, //Alpha = 1
        Out // Alpha = 0
    }
    #endregion

    #region FADE
    public IEnumerator Fade(FadeDirection fadeDirection)
    {
        fadeOutUIGameobjectImage.SetActive(true);

        float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0;
        float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1;
        if (fadeDirection == FadeDirection.Out)
        {
            while (alpha >= fadeEndValue)
            {
                SetColorImage(ref alpha, fadeDirection);
                yield return null;
            }
            fadeOutUIGameobjectImage.SetActive(false);
        }
        else
        {
            fadeOutUIGameobjectImage.SetActive(true);
            while (alpha <= fadeEndValue)
            {
                SetColorImage(ref alpha, fadeDirection);
                yield return null;
            }
        }
    }
    #endregion

    #region HELPERS
    public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection, string sceneToLoad)
    {
        yield return Fade(fadeDirection);
        SceneManager.LoadScene(sceneToLoad);

        SceneManager.sceneLoaded += SceneManager_sceneLoaded;
    }

    private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
    {
        if (menuController.loading == true)
        {
            var saveLoad = GameObject.Find("Save System").GetComponent<SaveLoad>();
            saveLoad.Load();
        }
    }

    private void SetColorImage(ref float alpha, FadeDirection fadeDirection)
    {
        if(fadeOutUIImage == null)
        {
            fadeOutUIImage = fadeOutUIGameobjectImage.GetComponent<Image>();
        }

        fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, alpha);
        alpha += Time.deltaTime * (1.0f / fadeSpeed) * ((fadeDirection == FadeDirection.Out) ? -1 : 1);
    }
    #endregion
}

At the top I did :

private MenuController menuController;

Then inside the event SceneManager_sceneLoaded I did at line 67 :

if (menuController.loading == true)

but I didn’t make any reference to the MenuController script even if it’s not destroyed.
so loading will be null here I guess.

The idea is to use global in my project with the loading bool flag variable to find if the game is loading or if a new game started.

javascript – ¿Cómo puedo asignar un valor select a una variable y que esta no sea undefined?

Estoy con un proyecto, simple. Quiero que un select tenga 3 datos 10, 20 y 40. Que por defecto cargue 10 y que con cada selección me actualice una variable que usaré para crear un Array. Concretame, 10, 20 y 40, son el numero de elementos que recogerá de un array más grande (preguntas).

Si lo pico a mano, funciona, si lo pongo así… nada.
Gracias de antemano a quien me de un poco de luz 🙂

window.onload = function() {
    fillBook();
}

var first_select;

function fillBook(){    
   first_select = document.getElementById('first-select').value;
   console.log(first_select);
}

//db_preguntas
var preguntas = (
    "Q_1", 
    "Q_2", 
    "Q_3",
    //... hay muchas

);
//db_respuestas
var respuestas = (
    ("CORRECTA r1_1", "incorrecta r2_1", "incorrecta r3_1", "incorrecta r4_1"),
    ("CORRECTA r1_2", "incorrecta r2_2", "incorrecta r3_2", "incorrecta r4_2"),
    ("CORRECTA r1_3", "incorrecta r2_3", "incorrecta r3_3", "incorrecta r4_3"),
    //... hay muchas

);

var n_Qs = first_select; //***esta es la variable de la discordia ******//

n_QsTOT = preguntas.length;
    
    const arr_Qs = new Array(preguntas);
    for (let i = 0; i < preguntas.length - 1; i++) {
        arr_Qs(i) = i + 1;
    }
    arr_Qs.sort(() => Math.random() > 0.5 ? 1 : -1);
    const newArray_Q = arr_Qs.slice(0, n_Qs); //nuevo Array: newArray_Q

    function logArrayElements(i, index, newArray_Q) {
        console.log("Q("+index+ ") = "+i);
    }
    newArray_Q.forEach(logArrayElements);
    <select id="first-select" onchange="fillBook()">
        <option value="10" selected>10 preguntas</option>
        <option value="20">20 preguntas</option>
        <option value="40">40 preguntas</option>
    </select>

theming – How to use a Twig variable as View name in drupal_view() Twig Tweaks function?

This works:

{{ drupal_view('nursing_resource_blog_teasers', 'block_1') }

But this doesn’t:

{% set view_name = "nursing_resource_blog_teasers" %}
{{ drupal_view(view_name , 'block_1') }

It appears that drupal_view() isn’t allowing a variable as the View name. Is there a way to make this work?

troubleshooting – use of ND Variable filter

I am an amateur photographer and I tested a ND 2-400 variable filter-at its maximum 8 2/3 stops-for a low light landscape scenery.My Nikon d610 suggested data were aperture 4.0 ,shutter speed 0.4s,iso 100 without the filter and the exposure calculator app on my mobile gave me a time of shooting of 205 s.However photo was black and remained black even when I exceeded the time of shooting up to 5 minutes and more.
Something went wrong and I need some advice on this.

equation solving – How to grab output from Reduce into a variable

I use Reduce to solve an 3rd order equation, and the output is given as the OR’d combination the solution variable. Normally, I can do a replacement to assign the value to a variable, but that doesn’t work on Reduce. I found that I need to use ToRules to do so, but I still can’t get it to work.

Vout =Vin/(C1*C2*L1*R1*s^3 + C1*R1*s + C2*L1*s^2 + C2*R1*s + 1) 
s=(ImaginaryI) (Omega);
values={
 R1->2000,
 C1 -> 10e-9,
 L1 -> 500u,
 C2 -> 1.2n
};   
 sol2=Reduce(ComplexExpand(Im(Vout/Vin/.values))==0,(Omega)) 

Here’s the output:

enter image description here

Normally, I’d do

(Omega) = (Omega) /. sol2((3))

to grab the 3rd item from the similar list resulting from a Solve function. However, Reduce doesn’t provide a list, so it doesn’t work. How do I use ToRules correcty? or is there another way to grab “any” specific output from a Reduce function?

reference request – Identities for laguerre polynomials not involving x as multiplicative variable

Are there other recursion relations for the associated Laguerre polynomials $L_n^{(alpha)} (x)$
that allow to calculate $L_{n_1}^{(alpha)} (x)$ from $L_{n<n_1}^{(alpha+k)} (x)$, $L_{n<n_1}^{(alpha+m)} (x)…$ not involving x

$$ L_n^{(alpha)} (x) = sum_{i=0}^n (-1)^i {n+alpha choose n-i} frac{x^i}{i!}.$$

Similar to

$$ L_n^{(alpha)} (x) = L_n^{(alpha+1)} (x)-L_{n-1}^{(alpha+1)} (x) $$