Posted: 22nd Dec 2021 3:16
I am using a example for sliders to adjust game values and I do not know what value to use to change anything.

Here are the functions. I am testing to find the value to change with scrollval but this does nothing. I tried just about every value i can find.

SetObjectColor( Joseph, scrollval[1] , scrollval[2] , scrollval[3], 255 ), I tried c but this only works with every slider not just the ones I want.

in using this example

https://forum.thegamecreators.com/thread/227392#msg2663038

+ Code Snippet
function check_sliders(a,b)
        if spritehit => a and spritehit =< b
                    x = getspritex(ts)
                    y = getspritey(ts)
                    w = getspritewidth(ts)
                    h = getspriteheight(ts)
                    p = getpointerx()
                    pc = (p-x) / w * 100
                    c = pc * scrollmax[ts-a] / 100
                       
                        if getpointerx() > x and getpointerx() < x+w and getpointery() > y and getpointery() < y + h
                          setspriteposition(ts+1340,getpointerx()-(getspritewidth(ts+1340)/2),getspritey(spritehit))
                          settextstring(ts+1440,str(round(c)))
                            
                      SetObjectColor( Joseph, scrollval[1]  , scrollval[2] , scrollval[3], 255 )
                             
                             
                             print(c)
                        endif
        endif
      
endfunction

function createSlider(s,x,y,w,h,t as string,ts,tv as string, min, max)
 
    scrollx[s]=x
    scrolly[s]=y
    scrollw[s]=w
    scrollh[s]=h
    scrollsprh[s] = s + 10
    scrollsprv[s] = s + 1350
    scrolltext[s] = s + 1400
    scrollval[s] = s + 1450
    scrollmin[s] = Min 
    scrollmax[s] = max 
     
    createsprite(scrollsprh[s],img_bar)
    SetSpritePosition(scrollsprh[s],scrollx[s],scrolly[s])
    SetSpriteSize(scrollsprh[s],scrollw[s],scrollh[s])
     if s=>11 then SetSpriteVisible(scrollsprh[s],0)
     
    createsprite(scrollsprv[s],img_vbar)
    SetSpritePosition(scrollsprv[s],getspritex(scrollsprh[s]),getspritey(scrollsprh[s]))    
    SetSpriteSize(scrollsprv[s],1,GetSpriteHeight(scrollsprh[s])-1)
    if s=>11 then SetSpriteVisible(scrollsprv[s],0)
     
    scrollvaltext[s] = tv
    createtext(scrolltext[s],t)
    settextsize(scrolltext[s],ts)
    settextposition(scrolltext[s],getspritex(scrollsprh[s]), getspritey(scrollsprh[s]) - (ts -1))
    if s=>11 then SettextVisible(scrolltext[s],0)
    
    createtext(scrollval[s],t)
    settextsize(scrollval[s],ts)
    settextposition(scrollval[s],getspritex(scrollsprh[s]), getspritey(scrollsprh[s]) + (ts + 3))
    settextstring(scrollval[s],scrollvaltext[s])
    if s=>11 then SettextVisible(scrollval[s],0)
    
    
    
endfunction
Posted: 22nd Dec 2021 19:15
I found that code to be a little bit confusing as well and decided to put my own little slider include file together. It may or may not be as performant, but you might find it easier to use.

Slider.agc
+ Code Snippet
// -----------------------------------
// Simple Horizontal Slider module
// by Hendron
// -----------------------------------

// adjust to change slider appearance
#constant SLIDER_BAR_WIDTH 200.0
#constant SLIDER_BAR_HEIGHT 8.0
#constant SLIDER_BAR_COLOR MakeColor(128,  128,  128)
#constant SLIDER_HANDLE_WIDTH 8.0
#constant SLIDER_HANDLE_HEIGHT 24.0
#constant SLIDER_HANDLE_COLOR MakeColor(128,255,128)
#constant SLIDER_TEXT_SIZE 16

type tSliderResource
  imgBar
  imgHandle
  sliderList as tSlider[]
  hotIdx
endtype

type tSlider
  name as string
  min as float
  max as float
  current as float
  x as float
  y as float
  sprBar
  sprHandle
  txtLabel
  txtValue
endtype

global _sliderResource as tSliderResource

// must be called before using other functions
function InitSliders()
  _sliderResource.imgBar = _SliderCreateBarImage()
  _sliderResource.imgHandle = _SliderCreateHandleImage()
  _sliderResource.hotIdx = -1
endfunction

function CreateSlider(name$, min#, max#, x#, y#)
  inst as tSlider
  inst.name = name$
  inst.min = min#
  inst.max = max#
  inst.x = x#
  inst.y = y#
  inst.current = inst.min
  // setup sprites
  inst.sprBar = CreateSprite(_sliderResource.imgBar)
  SetSpriteOffset(inst.sprBar, 0, GetSpriteHeight(inst.sprBar)/2)
  inst.sprHandle = CreateSprite(_sliderResource.imgHandle)
  SetSpriteOffset(inst.sprHandle,SLIDER_HANDLE_WIDTH/2,0)
  SetSpritePosition(inst.sprHandle, x#, y#)
  SetSpritePositionByOffset(inst.sprBar, x#, y# + (GetSpriteHeight(inst.sprHandle)/2))
  // setup texts
  inst.txtLabel = CreateText(name$)
  SetTextSize(inst.txtLabel,  SLIDER_TEXT_SIZE)
  SetTextPosition(inst.txtLabel, x#, y# + SLIDER_HANDLE_HEIGHT/2 + SLIDER_TEXT_SIZE)
  inst.txtValue = CreateText(str(inst.min,2))
  SetTextSize(inst.txtValue, SLIDER_TEXT_SIZE)
  SetTextAlignment(inst.txtValue, 2)
  SetTextPosition(inst.txtValue, x# + SLIDER_BAR_WIDTH, GetTextY(inst.txtLabel))
  // add to slider list
  _sliderResource.sliderList.insertSorted(inst)
endfunction

// remove slider and its resources
function DeleteSlider(name$)
  idx = _sliderResource.sliderList.find(name$)
  if idx > -1
    DeleteSprite(_sliderResource.sliderList[idx].sprBar)
    DeleteSprite(_sliderResource.sliderList[idx].sprHandle)
    DeleteText(_sliderResource.sliderList[idx].txtLabel)
    DeleteText(_sliderResource.sliderList[idx].txtValue)
    _sliderResource.sliderList.remove(idx)
  endif
endfunction

// call this at the beginning of every loop
function HandleSliders()
  if _sliderResource.hotIdx > -1
    _SliderHandleHot(_sliderResource.sliderList[_sliderResource.hotIdx])
  else
    if GetPointerPressed() = 1
      px# = GetPointerX()
      py# = GetPointerY()
      for i = 0 to _sliderResource.sliderList.length
        if GetSpriteHitTest(_sliderResource.sliderList[i].sprHandle, px#, py#) or GetSpriteHitTest(_sliderResource.sliderList[i].sprBar, px#, py#)
          _sliderResource.hotIdx = i
          exitfunction
        endif
      next i
    endif
  endif
endfunction

// get the current slider value
function GetSliderValue(name$)
  idx = _sliderResource.sliderList.find(name$)
  if idx > -1
    exitfunction _sliderResource.sliderList[idx].current
  endif
endfunction 0.0

// set the current slider value
function SetSliderValue(name$, value)
  idx = _sliderResource.sliderList.find(name$)
  if idx > -1
    if value > _sliderResource.sliderList[idx].max then value = _sliderResource.sliderList[idx].max
    if value < _sliderResource.sliderList[idx].min then value = _sliderResource.sliderList[idx].min
    _sliderResource.sliderList[idx].current = value
    _SliderUpdateAppearance(_sliderResource.sliderList[idx])
  endif
endfunction

// set custom bar image
function SetSliderBarImage(name$, img)
  idx = _sliderResource.sliderList.find(name$)
  if idx > -1
    SetSpriteImage(_sliderResource.sliderList[idx].sprBar, img)
  endif
endfunction

// set custom handle image
function SetSliderHandleImage(name$, img)
  idx = _sliderResource.sliderList.find(name$)
  if idx > -1
    SetSpriteImage(_sliderResource.sliderList[idx].sprHandle, img)
  endif
endfunction

// --------------------------------------------------------------------------
// The following functions are not meant to be used outside of this file

// handle slider that is currently "hot" (pointer pressed on it)
function _SliderHandleHot(inst ref as tSlider)
  if GetPointerState() = 1
    px# = GetPointerX()
    sx# = inst.x
    t# = ((px# - sx#) / SLIDER_BAR_WIDTH)
    if t# > 1.0 then t# = 1.0
    if t# < 0.0 then t# = 0.0
    range# = inst.max - inst.min
    inst.current = inst.min + (range# * t#)
    _SliderUpdateAppearance(inst)
  else
    _sliderResource.hotIdx = -1
  endif
endfunction

// update the slider's sprite positions and text
function _SliderUpdateAppearance(inst ref as tSlider)
  t# = (inst.current - inst.min) / (inst.max - inst.min)
  SetTextString(inst.txtValue, str(inst.current,2))
  SetSpritePosition(inst.sprHandle, inst.x + (SLIDER_BAR_WIDTH - SLIDER_HANDLE_WIDTH / 2) * t#, GetSpriteY(inst.sprHandle))
endfunction

// create a default bar image
function _SliderCreateBarImage()
  ClearScreen()
  DrawBox(0,0,SLIDER_BAR_WIDTH,SLIDER_BAR_HEIGHT,SLIDER_BAR_COLOR,SLIDER_BAR_COLOR,SLIDER_BAR_COLOR,SLIDER_BAR_COLOR,1)
  Render()
  imgId = GetImage(0,0,SLIDER_BAR_WIDTH,SLIDER_BAR_HEIGHT)
endfunction imgId

// create a default handle image
function _SliderCreateHandleImage()
  ClearScreen()
  DrawBox(0,0,SLIDER_HANDLE_WIDTH,SLIDER_HANDLE_HEIGHT,SLIDER_HANDLE_COLOR,SLIDER_HANDLE_COLOR,SLIDER_HANDLE_COLOR,SLIDER_HANDLE_COLOR,1)
  Render()
  imgId = GetImage(0,0,SLIDER_HANDLE_WIDTH,SLIDER_HANDLE_HEIGHT)
endfunction imgId
// -------------------------------------------------------------



and to test it out:
+ Code Snippet
#include "Slider.agc"

// setup window and create test object
SetWindowSize(1024, 768, 0)
SetVirtualResolution(1024, 768)
SetSyncRate(0, 0)
UseNewDefaultFonts(1)
obj = CreateObjectBox(10,10,10)

// must be called before any other slider functions
InitSliders()

// create some sliders
// name, min, max, x position, y position
CreateSlider("Red", 0, 255, 24, 16)
CreateSlider("Green", 0, 255, 24, 96)
CreateSlider("Blue", 0, 255, 24, 176)
CreateSlider("Angle", 0, 360, 24, 256)

// uncomment to test changing the slider images
//SetSliderHandleImage("Red", CreateImageColor(255,0,0,255))
//SetSliderHandleImage("Green", CreateImageColor(0,255,0,255))
//SetSliderHandleImage("Blue", CreateImageColor(0,0,255,255))

do
  // call this before retrieving any slider values
  HandleSliders()

  // press space to max out the sliders
  if GetRawKeyPressed(32)
    SetSliderValue("Red", 255)
    SetSliderValue("Green", 255)
    SetSliderValue("Blue", 255)
    SetSliderValue("Angle", 360)
  endif

  // apply slider values to object
  SetObjectColor(obj, GetSliderValue("Red"), GetSliderValue("Green"), GetSliderValue("Blue"), 255)
  SetObjectRotation(obj,0,GetSliderValue("Angle"),0)

  Sync()
loop
Posted: 23rd Dec 2021 4:49
hendron

Thank you, I will look at this and let you know how it works.

thank you for the time.
Posted: 23rd Dec 2021 5:56
Ok, I had to scale the sprites to my windows scale but this works perfectly.

I am so impressed.

Thank you so much hendron.