Jump to content

Question that is kinda a riddle


Recommended Posts

I'm trying to figure out the autoit representation of the following c++ code

Int a=6;

Int& ref_a=a

So then if ref_a changes a would change aswell. 

I'm essentially interested in taking an unknown variable passed into my function be an alias to a element inside of an array lol.  So that if the variable value passed into my function changes after the function is exited the value inside of the array element would change aswell.   

So in short

$a=3

Func($a)

Array[1]=$a

End func

Then if the value of $a changed after the function so would the value in the  element in the array.... I know it's a longshot but I figured it's worth a post.

I've used byref and that works great inside functions but I'm talking about outside of a function. Or possibly some other function.

Link to comment
Share on other sites

Something like this I guess

$a = 3
Local $aArray[1] = ["a"]
ConsoleWrite(Eval($aArray[0]) & @CRLF)
$a = 6
ConsoleWrite(Eval($aArray[0]) & @CRLF)

setAVariable($a, 25)
ConsoleWrite(Eval($aArray[0]) & @CRLF)


Func setAVariable(ByRef $a, $i)
    $a = $i
EndFunc

output

3

6

25

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

3 hours ago, jdelaney said:

Something like this I guess

$a = 3
Local $aArray[1] = ["a"]
ConsoleWrite(Eval($aArray[0]) & @CRLF)
$a = 6
ConsoleWrite(Eval($aArray[0]) & @CRLF)

setAVariable($a, 25)
ConsoleWrite(Eval($aArray[0]) & @CRLF)


Func setAVariable(ByRef $a, $i)
    $a = $i
EndFunc

output

3

6

25

this is working,  its definitely a move in the right direction.  Thankyou its very tricky.  

 

#include <Array.au3>


Global $array[1]=['temp'] , $UnknownVariable="random value", $temp


_aFunction($UnknownVariable)
ConsoleWrite(eval($array[0]))
;~ _ArrayDisplay($array)

$UnknownVariable=4456

_aFunction($UnknownVariable)
;~ _ArrayDisplay($array)
ConsoleWrite(eval($array[0]))

_aFunction("34235")
ConsoleWrite(eval($array[0]))
;~ _ArrayDisplay($array)


func _aFunction($var)
$temp=$var

EndFunc

this technique is sweet and I appreciate it for what it is but it still doesn't off the implicit connection im looking for.  I'm basically looking for this

int a=5;

int* b=&a;

*b=10;

at this point int a would also be =10.  This is part of the downside of not having access to variable pointers bc theres no way to monitor if a variable has changed without adding in some kinda constant loop that the whole point was to just monitor variables that had been passed into a previous function.  An the only way to make the connection is by forcing the user to pass the original variable without any value except for the string of its name.   I've seen the question asked about turning a variable name into a string b4 and apparently thats not possible?

 

 

 

 

 

Edited by markyrocks
Link to comment
Share on other sites

I don't know if the following is an appropriate way of using @genius257's "AutoItObject Pure AutoIt", and if this way can be useful to you, but this script shows how to "clone" "mirror" a variable (or better, an object)

; https://www.autoitscript.com/forum/topic/185720-autoitobject-pure-autoit/
#include <AutoItObject_Internal.au3>

$a = IDispatch()

$b = $a

$a.value = 1

MsgBox(0, '', $b.value)

$b.value = 0

MsgBox(0, '', $a.value)

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

On 1/9/2020 at 5:55 PM, markyrocks said:

the autoit representation of the following c++ code

Well, this is all linear, so.., anything that changes, will change in chronological order ( unless is Adlib or a registered call, but then use flags/globals ).
So don't get too caught up in the ways of C++ while scripting AutoIt.

My 2 cents :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...